首页 > 其他 > 详细

Alarm

时间:2016-08-05 21:28:06      阅读:134      评论:0      收藏:0      [点我收藏+]
A -- Alarm

Time Limit:1s Memory Limit:128MByte

Submissions:179Solved:62

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 (1k10000)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
题解:第n个素数的平方-n;
 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 }

 

Alarm

原文:http://www.cnblogs.com/llal/p/5742721.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!