湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han
2017-12-24 20:09
351 查看
题目描述
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; }
相关文章推荐
- 湖南大学ACM程序设计新生杯大赛(同步赛)L-Liao Han【打表规律+二分】
- 湖南大学ACM程序设计新生杯大赛(同步赛)L-Liao Han【打表规律+二分】
- 湖南大学ACM程序设计新生杯大赛(同步赛)H-Yuanyuan Long and His Ballons【公式】
- 湖南大学ACM程序设计新生杯大赛(同步赛)
- 湖南大学ACM程序设计新生杯大赛(同步赛)H - Yuanyuan Long and His Ballons
- 湖南大学ACM程序设计新生杯大赛(同步赛)D - Number
- 湖南大学ACM程序设计新生杯大赛(同步赛)I - Piglet treasure hunt Series 1
- 湖南大学ACM程序设计新生杯大赛(同步赛)H-Yuanyuan Long and His Ballons【公式】
- 湖南大学ACM程序设计新生杯大赛(同步赛) I-Piglet treasure hunt Series 1【BFS】
- 湖南大学ACM程序设计新生杯大赛(同步赛) I-Piglet treasure hunt Series 1【BFS】
- 湖南大学ACM程序设计新生杯大赛(同步赛)C - Do you like Banana ?
- 湖南大学ACM程序设计新生杯大赛(同步赛)G - The heap of socks
- 湖南大学ACM程序设计新生杯大赛(C-Do you like banana?)
- 湖南大学ACM程序设计新生杯大赛 - A Array
- 湖南大学ACM程序设计新生杯大赛(同步赛)A-Array 【证明+暴力】
- 湖南大学ACM程序设计新生杯大赛(同步赛)E - Permutation
- 湖南大学ACM程序设计新生杯大赛 - B Build
- 湖南大学ACM程序设计新生杯大赛(同步赛)C-Do you like Banana ? 【几何】
- 湖南大学ACM程序设计新生杯大赛 - E Permutation (匈牙利算法)
- 湖南大学ACM程序设计新生杯大赛(同步赛) D -Number 【打表+暴力】