zoukankan      html  css  js  c++  java
  • SPOJ AMR11E Distinct Primes 基础数论

    Arithmancy is Draco Malfoy's favorite subject, but what spoils it for him is that Hermione Granger is in his class, and she is better than him at it. Prime numbers are of mystical importance in Arithmancy, and Lucky Numbers even more so. Lucky Numbers are those positive integers that have at least three distinct prime factors; 30 and 42 are the first two. Malfoy's teacher has given them a positive integer n, and has asked them to find the n-th lucky number. Malfoy would like to beat Hermione at this exercise, so although he is an evil git, please help him, just this once. After all, the know-it-all Hermione does need a lesson.

    Input

    The first line contains the number of test cases T. Each of the next T lines contains one integer n.

    Output

    Output T lines, containing the corresponding lucky number for that test case.

    Constraints

    1 <= T <= 20
    1 <= n <= 1000

    Example

    Sample Input:
    2
    1
    2
    
    Sample Output:
    30
    42

    题意:找第n个由至少三个不同素因子组成的数。

    思路:n<=1000直接暴力打表预处理

    /** @Date    : 2016-12-11-19.01
      * @Author  : Lweleth (SoungEarlf@gmail.com)
      * @Link    : https://github.com/
      * @Version :
      */
    #include<bits/stdc++.h>
    #define LL long long
    #define PII pair
    #define MP(x, y) make_pair((x),(y))
    #define fi first
    #define se second
    #define PB(x) push_back((x))
    #define MMG(x) memset((x), -1,sizeof(x))
    #define MMF(x) memset((x),0,sizeof(x))
    #define MMI(x) memset((x), INF, sizeof(x))
    using namespace std;
    
    const int INF = 0x3f3f3f3f;
    const int N = 1e5+20;
    const double eps = 1e-8;
    
    
    int pri[N];
    int ans[10010];
    int c = 0;
    bool vis[N];
    int prime()
    {
        MMF(vis);
        for(int i = 2; i < N; i++)
        {
            if(!vis[i])
                pri[c++] = i;
    
            for(int j = 0; j < c && pri[j]*i < N; j++)
            {
                vis[i * pri[j]] = 1;
                if(i % pri[j] == 0)
                    break;
            }
        }
    }
    
    
    int main()
    {
        prime();
        int tot = 0;
        for(int i = 0; i <= 10000; i++)
        {
            int t = i;
            int cnt = 0;
            for(int j = 0; j < c && pri[j]*pri[j] <= t; j++)
            {
                if(t % pri[j] == 0)
                {
                    cnt++;
                    while(t % pri[j] == 0)
                        t /= pri[j];
                }
            }
            if(t > 1)
                cnt++;
            if(cnt >= 3)
                ans[tot++] = i;
        }
        int T;
        scanf("%d", &T);
        while(T--)
        {
            int n;
            scanf("%d", &n);
            printf("%d
    ", ans[n - 1]);
        }
        return 0;
    }
    
    
  • 相关阅读:
    free解释
    无损 JBIG2 编码库(Lossless JBIG2 Encoder)
    PDF补丁丁暂停更新
    PDF补丁丁将字符识别结果写入PDF文件功能即将完成
    PDF补丁丁0.3.3版:字符识别结果写入PDF文件功能邀请测试
    PDF补丁丁 0.3.3.58版修复打开、输出超大型PDF文件问题
    PDF补丁丁0.3.3版即将发布
    PDF补丁丁0.3.3.12 新增查看PDF文件隐藏对象及导出流对象功能
    PDF 补丁丁 0.3.3 正式版发布
    PDF 补丁丁0.3.3.20版新增JBIG2压缩功能,可为扫描PDF瘦身
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/6163255.html
Copyright © 2011-2022 走看看