1010 - Alarm
Time Limit:1s Memory Limit:128MByte
DESCRIPTION
Given a number sequence [3,7,22,45,116,...]
. Please tell me the k
-th number.
INPUT
A number T (T<100)
indicates the number of the input cases. Then for each case there only is one integer k (1≤k≤10000)
.
OUTPUT
For each case, ouput the k
-th number of the sequence in one line.
SAMPLE INPUT
2
1
4
SAMPLE OUTPUT
3
45
第一次做这种题,我的内心是崩溃的找规律找规律 ans=prime(n)^2-n;
来一个数列查找链接 http://oeis.org/
#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <cmath> #include <vector> #include <algorithm> using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>y?x:y) #define min(x,y) (x<y?x:y) #define mem(a) (memset(a,0,sizeof(a))) typedef long long ll; ll a[105000]; ll vis[10006]; void getprime() { memset(a,0,sizeof(a)); a[1]=1; for(ll i=2;i<105000;i++) { if(a[i]==1) continue; for(ll j=2;j*i<105000;j++) a[j*i]=1; } ll ans=1; for(ll i=2;i<105000;i++) { if(!a[i]) vis[ans++]=i; if(ans>=10002) break; } } int main() { ll t,n; scanf("%lld",&t); getprime(); while(t--) { scanf("%lld",&n); printf("%lld\n", vis[n]*vis[n]-n); } }
时间: 2024-11-06 04:13:38