标签:
Time Limit:1s Memory Limit:128MByte
Submissions:179Solved:62
Given a number sequence [3,7,22,45,116,...][3,7,22,45,116,...]. Please tell me the kk-th number.
A number T (T<100)T (T<100) indicates the number of the input cases. Then for each case there only is one integer k (1≤k≤10000)k (1≤k≤10000).
For each case, ouput the kk-th number of the sequence in one line.
2 1 4
3 45
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<iostream> 5 using namespace std; 6 #define N 1000000 7 int su[N+11]={1,1}; 8 long long a[N]; 9 void judge() 10 { 11 memset(a, 0, sizeof(a)); 12 int i ,j; 13 int t = 1; 14 for(i = 2;i <= N ;i++) 15 { 16 if( su[i]==1) 17 continue; 18 else 19 { 20 a[t++]=i; 21 for(j = i*2;j <= N;j+=i) 22 su[j] = 1; 23 } 24 25 } 26 27 } 28 int main() 29 { 30 int n,p; 31 scanf("%d",&n); 32 judge(); 33 while(n--) 34 { 35 scanf("%d",&p); 36 long long ans = a[p]*a[p]-p; 37 printf("%lld\n",ans); 38 } 39 40 return 0; 41 }
标签:
原文地址:http://www.cnblogs.com/llal/p/5742721.html