码迷,mamicode.com
首页 > 其他好文 > 详细

Alarm

时间:2016-08-05 21:28:44      阅读:144      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!