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;
    }
    
    
  • 相关阅读:
    Applet
    Tutorial中代码的区别及不同效果
    Session
    代码解析&Filter用户授权例子
    Web的后台运作过程
    XML
    数据库
    spring常用注解
    spring mvc 常用注解
    @requestMapping
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/6163255.html
Copyright © 2011-2022 走看看