Alarm(找规律)

来源:互联网 发布:比利时保拉王后知乎 编辑:程序博客网 时间:2024/05/21 22:23
Alarm


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
214
SAMPLE OUTPUT
345
位置所对应质数的平方减去位置大小
[cpp] view plain copy
print?在CODE上查看代码片派生到我的代码片
  1. #include<stdio.h>  
  2. #include<algorithm>  
  3. #include<iostream>  
  4. using namespace std;  
  5.  long long  a[10000000],b[3000000],i,j;  
  6. int main()  
  7. {  
  8.     long long  n,m,t;  
  9.     long long  l=1;  
  10.     for(i=2;i<=10000000;i++)  
  11.     {  
  12.     if(a[i]==0)  
  13. {for(j=i+i;j<10000000;j=j+i)  
  14.     a[j]=1;}}  
  15.     for( i=2;i<10000000;i++)  
  16.     {if(a[i]==0)  
  17.     b[l++]=i*i;}  
  18.     scanf("%lld",&t);  
  19.     while(t--)  
  20.     {  
  21.     scanf("%lld",&n);  
  22.    printf("%lld\n",b[n]-n);  
  23.     }  
  24. }  
0 0
原创粉丝点击