玲珑杯热身赛A--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
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
", a[n]*a[n]-n);
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/daydayupacm/p/5742723.html