A - A Math Problem

本文参考自: 原文地址

You are given a positive integer n, please count how many positive integers k satisfy kknkk≤n
InputThere are no more than 50 test cases.  Each case only contains a positivse integer n in a line.  1n10181≤n≤1018  OutputFor each test case, output an integer indicates the number of positive integers k satisfy kknkk≤n in a line.Sample Input
1
4
Sample Output
1
2

解题思路:对于这个题,一点是数据很大,所以记得开long long,我第一次忘记开了,WA了一发,然后就是计算一下10的18次方附近的数值,会发现是15 的 15 和16的 16 之间所以打个一小小的表就可以了
#include<stdio.h>
#include<string.h>
int main()
{
	long long int a[51];
	for(long long int i = 1; i < 16;i++)
	{
		a[i] = 1;
		for(long long int j = 1; j <= i;j++)
		{
			a[i] = a[i]*i;
		}
	}
	
	
	long long int n;
	while(~scanf("%lld",&n))
	{
		int ans = 0;
		for(int i = 1; i < 16;i++)
		{
			if(n >= a[i])
			ans++;
			if(n < a[i])
			break;
		}
		printf("%d\n",ans);
		
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/running987/article/details/81429841