博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ACM/ICPC 2011 Asia-Amritapuri Site / E Distinct Primes(求数的素因子)
阅读量:4430 次
发布时间:2019-06-07

本文共 1764 字,大约阅读时间需要 5 分钟。

ACM International Collegiate Programming Contest, Asia-Amritapuri Site, 2011

 

Problem E: 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 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

 

分析:

 

简单模拟题。就是注意筛法求素数和怎么求一个数的素因子

 

代码:

 

View Code
#include 
#include
#include
#include
#include
using namespace std;#define MAX 50000int noprime[MAX];void Prime(int n){ int k; noprime[0]=noprime[1]=1; noprime[2]=0; for (int i=2;i
=3) break; while (n%i==0) n/=i; } if (num>=3) return true; else return false;}int main(){ int t; cin>>t; Prime(MAX); while (t--) { int n; cin>>n; int num=0; int pre=29; for (int i=pre+1;i<=42000;i++) if (judge(i)) { pre=i; num++; if (num==n) { cout<
<

转载于:https://www.cnblogs.com/AbandonZHANG/archive/2012/07/18/2598398.html

你可能感兴趣的文章
batch 常用命令
查看>>
centos7 openfiles问题
查看>>
StackExchange.Redis 官方文档(五) Keys, Values and Channels
查看>>
扫描目录下的文件并拼接在一起
查看>>
ELK 分布式日志处理 10.12
查看>>
Java虚拟机详解05----垃圾收集器及GC参数
查看>>
7. 单位,移动布局
查看>>
inux中bin与sbin目录的作用及区别介绍
查看>>
USACO 3.1 Contact
查看>>
Office之什么是高内聚低耦合
查看>>
一些奇怪的问题求回答
查看>>
这些年踩过的坑
查看>>
iOS开发拓展篇——如何把项目托管到GitHub
查看>>
性能优化之数据库优化
查看>>
《Cracking the Coding Interview》——第1章:数组和字符串——题目5
查看>>
D - F(x)
查看>>
发现一个很不错的东西!--百度网盘外链,下载速度很不错
查看>>
[Machine Learning]matplotlib
查看>>
[leetcode]523. Continuous Subarray Sum
查看>>
敏捷结果30天之第三天:用三个故事驱动你的一天
查看>>