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 (1≤k≤10000)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
题意很简单,就是找规律,通过规律我们可以发现:

然后打表就可以过啦~

#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; }
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步