Problem DescriptionYou are given a positive integer n, please count how many positive integers k satisfy kk≤n . InputThere are no more than 50 test cases. OutputFor each test case, output an integer indicates the number of positive integers k satisfy kk≤n in a line. Sample Input1 4 Sample Output1 2 |
直接快速幂解决。。
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
ll qpow(ll a, ll b) {
ll ans = 1;
ll k = a;
while(b) {
if(b&1) {
ans = ans*k;
}
k = k*k;
b >>= 1;
}
return ans;
}
int main() {
ll n;
while(scanf("%lld", &n) != EOF) {
int sum = 0;
for(int i = 1;i <= 15; i++) {
if(qpow(i, i) <= n) {
sum ++;
}
}
printf("%d\n", sum);
}
return 0;
}