k的k次方问题

A Math Problem
You are given a positive integer n, please count how many positive
integers k satisfy k的k次方≤n.

Input
There are no more than 50 test cases.
Each case only contains a positivse integer n in a line.
1≤n≤10的18 次方

(注意,longlong范围 2的64次方===16的16次方(longlong 1.8*10的19次方)首先必须要用longlong存n;
其次结果肯定不会达到16;至多15;用一个数列来列举1~15的k的k次方)

Output

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

Sample Input
1
4

Sample Output
1
2

题意:
给你一个数n,求有多少个正整数k满足k的k次方小于等于n

AC代码

​#include <bits/stdc++.h>
using namespace std;
long long a[16];
int main()
{
    int i=0,j=0;
    for( i=1; i<16; i++)
    {
        long long  x=1;
        for( j=1; j<=i; j++)
        {
            x*=i;
        }
        a[i]=x;
    }

    long long  n;
    while(scanf("%lld",&n)!=EOF)
    {
        int ans=0;
        for(int k=1; k<=15; k++)
        {
            if(a[k]<=n)ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}
​

猜你喜欢

转载自blog.csdn.net/qq_43484493/article/details/86512314
k