A -- Alarm
Time Limit:1s Memory Limit:128MByte
![](https://i-blog.csdnimg.cn/blog_migrate/07aa8295a607a2bb5346851789634dd4.png)
【思路】找规律:the k-th = 第k个素数^2 - k;
3=2^2-1 7=3^2-2 22=5^2-3 45=7^2-4......
AC代码:
#include<cstdio>
#define H 1000005
long long s[H]={1,1};
long long x[H];
void sushu()
{
long long i, j;
for(i = 2; i <= H; i++)
{
if(s[i] == 1) continue;
for(j = i*2; j <= H; j=j+i)
s[j] = 1;
}
}
void fun()
{
long long i, j = 1;
for(i = 2; i <= H; i++)
{
if(s[i] == 0)
{
x[j] = i*i-j;
j++;
}
}
}
int main()
{
sushu();
fun();
long long t, k;
scanf("%lld", &t);
while(t--)
{
scanf("%lld", &k);
printf("%lld\n", x[k]);
}
return 0;
}