A Math Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 729 Accepted Submission(s): 305
Problem Description
You are given a positive integer n, please count how many positive integers k satisfy
kk≤n
.
Input
There are no more than 50 test cases.
Each case only contains a positivse integer n in a line.
1≤n≤1018
Each case only contains a positivse integer n in a line.
1≤n≤1018
Output
For each test case, output an integer indicates the number of positive integers k satisfy
kk≤n
in a line.
Sample Input
1 4
Sample Output
1 2
Source
题意:给你一个n,求有多少个k满足k^k<=n
解题思路:暴力即可
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
#include <functional>
using namespace std;
#define LL long long
const int INF = 0x3f3f3f3f;
LL n;
LL qpow(LL x, LL y)
{
LL ans = 1;
while (y)
{
if (y & 1) ans *= x;
y >>= 1;
x *= x;
}
return ans;
}
int main()
{
while (~scanf("%lld", &n))
{
int sum = 0;
for (long long i = 1; i <= 15; i++)
{
if (qpow(i, i) > n) break;
sum++;
}
printf("%d\n", sum);
}
return 0;
}