您的位置:首页 > 其它

A -- Alarm

2016-08-05 21:20 113 查看
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
#include<stdio.h>#include<string.h>int su[1000000]={1,1};     int i,j,l=0;     int num[10001];void  h(){memset(su,0,sizeof(su));for(i=2;i<=1000000;i++){if(su[i]==1)continue;for( j=i*2;j<=1000000;j+=i)su[j]=1; }}void hh(){memset(num,0,sizeof(num));for(i=1;i<10001;i++){for(j=2;j<1000000;j++){if(!su[j]){su[j]=1;num[i]=j;break;}}}}int main(){int t,k;long long sum;h();hh();scanf("%d",&t);while(t--){scanf("%d",&k);sum=(long long)num[k]*num[k]-k; printf("%lld\n",sum);}return 0;}
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: