Alarm
Time Limit:1s Memory Limit:128MByte
Submissions:205Solved:72
DESCRIPTION
Given a number sequence [3,7,22,45,116,...][3,7,22,45,116,...]. Please tell me the kk-th number.
INPUT
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).
OUTPUT
For each case, ouput the kk-th number of the sequence in one line.
SAMPLE INPUT
2 1 4
SAMPLE OUTPUT
3 45
规律:3=2^2-1 7=3^2-2 22=5^2-3 45=7^2-4......
#include<cstdio> #include<algorithm> using namespace std; long long su[1000010]={1,1}; long long zhensu[1000010]; void dabiao() { for(long long i=2;i<=1000000;i++) { if(su[i]==1) continue; for(long long j=2*i;j<=1000000;j=j+i) { su[j]=1; } } } void suansu() { long long j=1; for(long long i=2;i<=1000000;i++) { if(su[i]==0){ zhensu[j]=i; j++; } } } int main() { dabiao(); suansu(); long long t,k; scanf("%lld",&t); while(t--) { scanf("%lld",&k); printf("%lld\n",zhensu[k]*zhensu[k]-k); } return 0; }