HDU - 6182 A Math Problem (打表)

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6182

题目 

You are given a positive integer n, please count how many positive integers k satisfy kk≤nkk≤n. 

Input

There are no more than 50 test cases. 

Each case only contains a positivse integer n in a line. 

1≤n≤10181≤n≤1018 

Output

For each test case, output an integer indicates the number of positive integers k satisfy kk≤nkk≤n in a line.

Sample Input

1
4

Sample Output

1
2

注意 pow是对于浮点数进行的,如果是整型可能会导致精度丢失,所以不要用pow打表

AC代码

#include<iostream>
#include<cmath>
using namespace std;
int main()
{   long long s[17]={1,4,27,256,3125,46656,823543,16777216,387420489,10000000000,285311670611,8916100448256,302875106592253,11112006825558016,437893890380859375};
    long long n;
    while(cin>>n){
        int sum=0;
        int i=0;
        while(s[i]<=n&&i<15){
            i++;
            sum++;
        }
        cout<<sum<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37291934/article/details/89337216
今日推荐