zoukankan      html  css  js  c++  java
  • 玲珑学院 1010

    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 (1k10000)

    .
    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
    ", vis[n]*vis[n]-n);
        }
    }
  • 相关阅读:
    17-电话号码字母的组合
    16-最接近的三数之和
    牛客网上的java面经,JVM
    15-三数之和
    mybatis 懒加载不生效
    @ControllerAdvice
    异常
    @ExceptionHandler处理异常
    spring aop annotation
    return 与 system.exit(0) 区别
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7182233.html
Copyright © 2011-2022 走看看