时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
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
分析:打表找个规律。
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#define ll long long int
using namespace std;
const ll maxn = 1e18;
const ll m = 2e9+10;
//void init() {
// ll tmp = 3; int i;
// ll ans = 0;
// for (i = 1;; i++) {
// if (ans > maxn) break;
// ans += tmp;
// a[i] = ans;
// tmp += 2;
// }
// len = i-1;
//}
ll judge(ll x) {
return x*(3 + x * 2 + 1)/2;
}
int main() {
ll n;
while (scanf("%lld", &n) && n) {
int L = 1, R = m ,mid;
while (L < R) {
mid = (L + R) / 2;
if (judge(mid)>= n) {
R = mid;
}
else {
L = mid + 1;
}
}
printf("%d\n", L);
}
return 0;
}