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这个题的意思是说,给你一个n,找出有几个k的k次方小于等于n。这个题注意16的16次方就超过long long的范围,所以只取到15的15次方。#include<stdio.h> long long int a[50]; int main(){ 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; } // printf("%lld\n",a[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); } }