标签:
Given a number sequence [3,7,22,45,116,...][3,7,22,45,116,...]. Please tell me the kk-th number.
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).
For each case, ouput the kk-th number of the sequence in one line.
2 1 4
3 45
题意很简单,就是找规律,通过规律我们可以发现:
然后打表就可以过啦~
#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include<algorithm> using namespace std; const int maxn=1000007; const int INF=0x3f3f3f3f; long long v[maxn], a[maxn], k; void Isprime() { memset(v, 0, sizeof(v)); for(int i=2; i<maxn; i++) { if(v[i]==0) { a[k++]=i; for(int j=i+i; j<maxn; j+=i) v[j]=1; } } } int main() { k=1; Isprime(); int T; scanf("%d", &T); while(T--) { int n; scanf("%d", &n); printf("%lld\n", a[n]*a[n]-n); } return 0; }
标签:
原文地址:http://www.cnblogs.com/daydayupacm/p/5742723.html