首页 > 其他 > 详细

玲珑杯热身赛A--Alarm (找规律)

时间:2016-08-05 21:26:15      阅读:140      评论:0      收藏:0      [点我收藏+]

 

 

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\n", a[n]*a[n]-n);
    }
    return 0;
}
View Code

 

玲珑杯热身赛A--Alarm (找规律)

原文:http://www.cnblogs.com/daydayupacm/p/5742723.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!