湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han

题目描述

Small koala special love LiaoHan (of course is very handsome boys), one day she saw N (N<1e18) guys standing in a row, because the boys had some strange character,The first time to Liao them will not be successful, but the second time will be successful; third times to Liao them  will not be successful, but the fourth time will be successful;....... By analogy (toxic psycho)

So the little koala burst odd thought of a fancy up method. The N is the sum of handsome boys, and labeled from 1 to N, starting from the first guy, whose number is 1, she will Liao all the boys whose number is Multiple of 1, then number 2 and all the boys whose number is Multiple of 2(toxic method)

Later, little Kola found that some handsome guys did not get her Liao, she asked the smart you to help her look for how many handsome guys did not successfully be Liaoed?

输入描述:

Multiple groups of Case. (no more than 10000 groups)Each group of data is 1 lines, with an integer N per line.The N is 0 at the end of the input.

输出描述:

Each group of Output1 rows, a number of 1 lines representing the number of boys with no Liao to the group of data.

示例1

输入

1
2
3
4
0

输出

1
1
1
2

题解

规律。

暴力打表后会发现有规律,答案就是$\sqrt{n}$,比赛的时候写了个二分...

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

long long n;

bool check(long long x) {
  if((2LL + x) * x >= n) return 1;
  return 0;
}

int main() {
  while(~scanf("%lld", &n)) {
    if(n == 0) break;
    long long L = 1, R = 1e9, ans;
    while(L <= R) {
      long long mid = (L + R) / 2;
      if(check(mid)) ans = mid, R = mid - 1;
      else L = mid + 1;
    }
    printf("%lld\n", ans);
  }
  return 0;
}

  

时间: 2024-08-01 18:23:14

湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han的相关文章

湖南大学ACM程序设计新生杯大赛(同步赛)B - Build

题目描述 In country  A, some roads are to be built to connect the cities.However, due to limited funds, only some roads can be built.That is to say,if the limit is 100$, only roads whose cost are no more than 100$ can be built. Now give you n cities, m r

湖南大学ACM程序设计新生杯大赛(同步赛)G - The heap of socks

题目描述 BSD is a lazy boy. He doesn't want to wash his socks, but he will have a data structure called 'socks heap'.By maintaining this structure, he can quickly pick out two of the most smelless socks from millions of socks everyday. As one of his good

湖南大学ACM程序设计新生杯大赛(同步赛)J - Piglet treasure hunt Series 2

题目描述 Once there was a pig, which was very fond of treasure hunting. One day, when it woke up, it found itself in a strange land of treasure. As for how to come in, or how to go out, no ways to know. Sad. The good news is, it was lucky that it got the

湖南大学第十四届ACM程序设计新生杯 Dandan&#39;s lunch

Dandan's lunch Description: As everyone knows, there are now n people participating in the competition. It was finally lunch time after 3 hours of the competition. Everyone brought a triangular bread. When they were going to eat bread, some people fo

湖南大学第十四届ACM程序设计新生杯 E.Easy Problem

E.Easy Problem Description: Zghh likes number, but he doesn't like writing problem description. So he will just give you a problem instead of telling a long story for it. Now given a positive integer x and k digits a1,a2,...,ak, can you find a positi

H. GSS and Simple Math Problem--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)

题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 题目描述 Given n positive integers , your task is to calculate the product of these integers, The answer is less than 输入描述: The first line of input is an integer n, the i-th of the following n lines contains the

哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练. 题解: E666 这个题是让求有多少个子串只含有6.寻找连续的6,然后用n*(n+1)/2求出这一段的子串个数,然后把每一段连续的加起来. 做的时候wa了很多次,原来是在n*(n+1)的地方已经超过int型了,所以需要设置类型为long long. #include <cstdio> #inc

2016广东工业大学新生杯决赛网络同步赛暨全国新生邀请赛 题解&amp;源码

Problem A: pigofzhou的巧克力棒 Description 众所周知,pigofzhou有许多妹子.有一天,pigofzhou得到了一根巧克力棒,他想把这根巧克力棒分给他的妹子们.具体地,这根巧克力棒长为 n,他想将这根巧克力棒折成 n 段长为 1 的巧克力棒,然后分给妹子们. 但是他妹子之一中的 15zhazhahe 有强迫症.若它每次将一根长为 k 的巧克力棒折成两段长为 a 和 b 的巧克力棒,此时若 a=b,则15zhazhahe会得到一点高兴值. pigofzhou想知

河南省第七届ACM程序设计大赛赛后总结

我们学校ACM集训开始于4月5号(清明节),5月25日在郑州解放军信息工程大学举办,集训耗时50天,但是感觉效果还行,但是也不是太好:我们也已经尽力了,虽然说只拿了个银牌,每份收获的背后,都会有辛勤的汗水,毕竟我们也努力了: 下面说说比赛中的问题:觉得吧,虽说模拟赛参加了很多,但是到了正式的比赛的时候,还是出现了紧张的情况,九点开始比赛,我们AC第一道题的时间是在十点半左右,题目不难而且曾经也做过啊,但是就是调试不好,越调试不好,心里就越急啊:刚开始看题的时间,我们都看了第一道题,意思也都明白,