ACM/ICPC 2011 Asia-Amritapuri Site / E Distinct Primes(求数的素因子)
来源:互联网 发布:西工大编程网址 编辑:程序博客网 时间:2024/06/04 19:33
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 <= 201 <= n <= 1000
Time Limit: 2 s
Memory Limit: 32 MB
Sample Input:
21
2
Sample Output:
3042
分析:
简单模拟题。就是注意筛法求素数和怎么求一个数的素因子。
代码:
#include <iostream>#include <cstring>#include <algorithm>#include <string>#include <cstdlib>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<n;i++) if (!noprime[i]) { k=i; while(k+i<n) { k=k+i; noprime[k]=1; } }}bool judge(int n){ int num=0; for (int i=2;i<40000;i++)//求一个数的素因子 if (!noprime[i]) { if (n%i==0) num++; if (num>=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<<i<<endl; break; } continue; } } return 0;}
- ACM/ICPC 2011 Asia-Amritapuri Site / E Distinct Primes(求数的素因子)
- ACM/ICPC 2011 Asia-Amritapuri Site / B Save the Students!(判断点在三角形中)
- 2015 ACM-ICPC Asia Amritapuri Regional Contest H
- Regionals 2011, Asia - Amritapuri
- 2016 ACM/ICPC Asia Regional Shenyang Online HDU 5901 Count Primes (模板 + 数论知识)★
- HDU 4714 Tree2cycle 求树的分叉数 && 2013 ACM/ICPC Asia Regional Online —— Warmup
- The 37th ACM/ICPC Asia Regional JinHua Site Online Contest - D(爆搜)
- CSU 1838: Water Pump(ACM-ICPC Asia Thailand National On-Site Programming Contest 2015)
- 4046 Panda(The 36th ACM/ICPC Asia Regional Beijing Site —— Online Contest)
- The 36th ACM/ICPC Asia Regional Shanghai Site 4016(dfs+剪枝)
- 【HDU5896 2016 ACM ICPC Asia Regional Shenyang Online E】【DP 排列组合 分治ntt】Running King n个点构成含环无向图的方案数.cp
- HDU 5901 Count Primes (模板 + 数论知识)——2016 ACM/ICPC Asia Regional Shenyang Online
- 2016 ACM-ICPC Asia Regional E – Similarity of Subtrees(dfs+hash)
- The 2012 ACM-ICPC Asia Changchun Regional Contest(problem E)
- 2017 ACM/ICPC Asia Regional Shenyang Online E题
- 2017 ACM/ICPC Asia Regional Qingdao Online HDU 6214 Smallest Minimum Cut(最小割的边数)
- 2011 大连网络赛 The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest 解题报告
- 4045 Machine scheduling(The 36th ACM/ICPC Asia Regional Beijing Site —— Online Contest)
- 如何设置WP7 bing地图显示中文
- ACM/ICPC 2011 Asia-Amritapuri Site / B Save the Students!(判断点在三角形中)
- 52个小技巧让WP手机使用更顺手
- 防止你的WP7手机偷跑流量——系统设置篇
- 总结常见网站服务器提权20种思路
- ACM/ICPC 2011 Asia-Amritapuri Site / E Distinct Primes(求数的素因子)
- 无题
- WP7软件安装 学会如何在WP7上安装软件
- 枚举(高新技术)
- 玩机技巧 WP功能解析之网络共享
- NPIV - 连接虚拟机与存储的桥梁
- 闪回数据库技术
- 链接脚本语言和C/C++之间的最好的工具:SWIG
- Android入门:ListView(SimpleAdapter实现)