UESTC 2016 Summer Training #2 Div.2 E 分解质因素(除了以后剩下的可能也是个素数)

E - E

Time Limit:3000MS     Memory Limit:1572864KB     64bit IO Format:%lld
& %llu

Submit Status Practice SPOJ
AMR11E

Description

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 nth 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 (STDIN):

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

Output (STDOUT):

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

Constraints:

1 <= T <= 20

1 <= n <= 1000

Time Limit: 2 s

Memory Limit: 32 MB

Sample Input:

2

1

2

Sample Output:

30

42

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 nth 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 (STDIN):

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

Output (STDOUT):

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

Constraints:

1 <= T <= 20

1 <= n <= 1000

Sample Input:

2

1

2

Sample Output:

30

42

Hint

Added by: Varun Jalan
Date: 2011-12-15
Time limit: 3s
Source limit: 50000B
Memory limit: 1536MB
Cluster: Cube (Intel G860)
Languages: All
Resource: Varun Jalan - ICPC Asia regionals, Amritapuri 2011

Source

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=121703#problem/E

My Solution

分解质因数, 至少有三个不同的质因数的数是lucky number, 用修改分解质因数的模版, 是只记录质因数个数就好,不用管是什么而且不同质因数个数大于等于3就return 3

用的分解质因素模版不知道为什么会WA, 改成 2~n, 暴力试除来分解质因数倒是可以⊙﹏⊙‖∣

原因, 对于2~sqrt(n)+1, 可能有剩余的大于 sqrt(n) +1的素数, 也就是还有大于sqrt(n)+1 的质因数, 所以试除全部的2~n比较好

//刚开始做的时候, 看成了,只能有三个不同质数构成的数, 然后就搞出个素数表,然后构造,然后用小根堆保存, 然后从那10000000多个根据要求的数中拿出最小的1000多个放到thisans[]里

//(┬_┬)成功浪费了一大堆时间

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
const int maxn = 20000 + 9;
int ans[maxn];

int factor(int n)
{
    int tot = 0;
    int temp, i, now;
    //temp = (int)((double)sqrt(n) + 1);
    now = n;
    for(int i = 2; i <= n; i++){ //!!!!!!为什么不能用temp呢
        if(now%i == 0){
            tot++;
            if(tot >= 3) return tot;
        }
        while(now%i == 0){
            now/=i;
        }
    }
    return tot;
}

int main()
{
    int t = 1, num = 2;
    while(t < 1009){
        if(factor(num) >= 3) {ans[t] = num; t++;}
        num++;

    }
    //cout<<factor(4588)<<endl;
    #ifdef LOCAL
    freopen("a.txt", "r", stdin);
    //freopen("b.txt", "w", stdout);
    #endif // LOCAL
    LL T, n;
    cin>>T;
    while(T--){
        cin>>n;
        cout<<ans[n]<<endl;

    }
    return 0;
}

Thank you!

------from ProLights

------from ProLights

时间: 2024-11-12 10:28:57

UESTC 2016 Summer Training #2 Div.2 E 分解质因素(除了以后剩下的可能也是个素数)的相关文章

UESTC 2016 Summer Training #1 Div.2

最近意志力好飘摇..不知道坚不坚持得下去.. 这么弱还瞎纠结...可以滚了.. 水题都不会做.. LCS (A) 水 LCS (B) 没有看题 Gym 100989C 水 1D Cafeteria (B) 不会捉 Gym 100989E 水 Gym 100989F 水 Mission in Amman (B) 没看题 Queue (A) 感觉题意理解得有问题啊 1 #include <iostream> 2 #include <cstdio> 3 #include <cstr

UESTC 2016 Summer Training #5 Div.2(未完待续)

A #include <cstdio> #include <cstring> #include <vector> #define MAXN 100005 #define mem(a) memset(a, 0, sizeof(a)) using namespace std; int TreeArray[MAXN], Left[MAXN], Right[MAXN], Fork[MAXN]; typedef vector<int> Ve; vector<Ve

UESTC 2016 Summer Training #2 Div.2 A dp、递推、多阶段问题

A - A Time Limit:336MS     Memory Limit:1572864KB     64bit IO Format:%lld & %llu Submit Status Practice SPOJ AMR11A Description Thanks a lot for helping Harry Potter in finding the Sorcerer's Stone of Immortality in October. Did we not tell you that

UESTC 2016 Summer Training #1 Div.2 E - Accepted Passwords 讨论

E - Accepted Passwords Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100989E Description standard input/output Islam is usually in a hurry. He often types his passwords incorrectly. He hates

UESTC 2016 Summer Training #1 Div.2 F - Mission in Amman (A) 动态维护(刷新:--、++)

F - Mission in Amman (A) Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100989F Description standard input/output You must have heard about Agent Mahone! Dr. Ibrahim hired him to catch the che

UESTC 2016 Summer Training #1 Div.2 L - Plus or Minus (A) dfs

L - Plus or Minus (A) Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100989L Description standard input/output AbdelKader enjoys math. He feels very frustrated whenever he sees an incorrect eq

UESTC 2016 Summer Training #1 Div.2 H - Queue (A) 贪心

H - Queue (A) Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100989H Description standard input/output After the data structures exam, students lined up in the cafeteria to have a drink and ch

UESTC 2014 Summer Training #18 Div.2

A.UVALive 6661 题意从1~N中选k个数,和为s的方案数 第一眼搜索,估计错状态量,又去yydp...浪费大量时间 数据很小的,状态数都不会超过2^N...直接dfs就过了 //state二进制表示选取的数 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; const int maxn = 200; in

UESTC 2014 Summer Training #3 Div.2

(更新中) A:ZOJ 3611 BFS+状态压缩 [题意]:给定一张n*m的图,图上每个点有如下情况:L,R,D,U:代表在该点上只能往它已经给定的方向前进.#,W:不能走到该点.$:走到该点,可以花两分钟得到一分值,然后可以从该点向任意方向走.0:走到该点后可以向任意方向走.然后给你起点和终点坐标,问是否能从起点走到终点,如果能,求出可获得的最大分值以及与之对应达到该最大分值所需的的最小时间花 费.(其中起点和终点坐标可以相同)[知识点]:BFS+状态压缩[题解]:我觉得超级棒的题!真心感觉