2017ACM/ICPC广西邀请赛 A Math Problem
A Math Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total
Submission(s): 0 Accepted Submission(s): 0
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
题解:完全是一道水题
10的18次方 所以我们使用long long int 长整数打表 记录i的i次方 我们可以发现当i=16的时候 16的16次方已经大于了10的18次方
直接打表循环判断一下就AC了
1 #include <iostream> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <algorithm> 5 #include <cstring> 6 #include <math.h> 7 using namespace std; 8 long long int a[20]; 9 long long int jug(int x) 10 { 11 long long int ans=1; 12 for(int i=1;i<=x;++i) 13 { 14 ans=ans*x; 15 } 16 return ans; 17 } 18 void init() 19 { 20 for(int i=1;i<20;++i) 21 { 22 a[i]=jug(i); 23 } 24 } 25 int main() 26 { 27 init(); 28 long long int n; 29 30 while(~scanf("%lld",&n)) 31 { 32 for(int i=1;i<=15;++i) 33 { 34 if(a[i]>n) 35 { 36 printf("%d\n",i-1); 37 break; 38 } 39 } 40 if(a[15]<=n) 41 printf("15\n"); 42 } 43 return 0; 44 } 45 //0ms AC
喜欢算法的dalao可以加QQ1345411028
作者:红雨
出处:https://www.cnblogs.com/52why
微信公众号: 红雨python