spoj 10232 Distinct Primes(打表)
来源:互联网 发布:域名记录类型 编辑:程序博客网 时间:2024/06/05 22:38
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
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
#include<stdio.h>#include<string.h>int p[10000];int a[10000];int lucky(int x){int num=0,i=2;while(x>1){if(x%i==0){num++;while(x%i==0)x/=i;}else{i++;while(p[i]){i++;}}}if(num>=3) return 1;return 0;}void sloved(){int i=0;int x=30;while(i<=1500){if(lucky(x)){a[++i]=x;}x++;}}int main(){int i,j;memset(p,0,sizeof(p));p[0]=p[1]=1; for(int i=2;i*i<10000;i++){if(!p[i]){for(int j=i*i;j<10000;j+=i){p[j]=1;} }}sloved();int t,n;scanf("%d",&t);while(t--){scanf("%d",&n);printf("%d\n",a[n]);}return 0;}
1 0
- spoj 10232 Distinct Primes(打表)
- SPOJ AMR11E - Distinct Primes 10232【素数打表】
- Distinct Primes 打表
- SPOJ - TAP2013H D - Horace and his primes 素数筛+素数分解+打表
- HDU 2161 Primes(素数打表)
- HDU 5104 Primes Problem(打表)
- hdu 4715 Difference Between Primes (打表 枚举)
- hdoj Primes Problem 5104 (素数打表&&技巧)
- Primes on Interval(素数打表+二分)
- HDU 5104 Primes Problem(素数打表)
- hdoj-5104Primes Problem(素数打表)
- spoj 694 Distinct Substrings(后缀数组)
- SPOJ 694 Distinct Substrings(后缀数组)
- SPOJ New Distinct Substrings(后缀数组)
- SPOJ DISUBSTR Distinct Substrings(后缀数组)
- hust Distinct Primes
- SPOJ - Distinct Substrings / SPOJ - New Distinct Substrings(后缀数组 - 不相同子串个数)
- HDU 4715 Difference Between Primes (打表)
- 为SQL增加自定义函数约束
- FreeBSD
- VI文本编辑器
- IO Visor:又一个开源项目横空出世
- 文章怎么还审核呢
- spoj 10232 Distinct Primes(打表)
- HTML <a>标签 title属性 鼠标悬停文字显示
- C#创建Windows Service(Windows 服务)基础教程
- 反射调用android系统级API函数
- Android设计模式系列-组合模式
- Hadoop之命令集合(全)
- Android 模拟器AVD,设置电池状态
- 深析静态链接库和动态链接库相同函数覆盖及库调用顺序问题
- 数据库常用