A -- Alarm
Time Limit:1s Memory Limit:128MByte
Submissions:216Solved:75
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
签到题,渣渣也就只会这道签到题
找规律第k个素数的平方-k ,打印素数表即可,
#include<stdio.h> #include<string.h> #include<algorithm> #define LL long long using namespace std; long long f[101000]; void init() { long long i,j,l=1; for(i=2;i<110000;i++) { for(j=2;j*j<=i;j++) if(i%j==0) break; if(j*j>i) f[l++]=i; } } int main() { long long t,k; scanf("%lld",&t); init(); while(t--) { scanf("%lld",&k); LL sum=f[k]*f[k]-k; printf("%lld\n",sum); } return 0; }