ZOJ 2723 Semi-Prime
2016-04-02 08:59
309 查看
Semi-Prime
Time Limit: 2 Seconds Memory Limit: 65536 KB
Prime Number Definition
An integer greater than one is called a prime number if its only positive divisors (factors) are one and itself. For instance, 2, 11, 67, 89 are prime numbers but 8, 20, 27 are not.
Semi-Prime Number Definition
An integer greater than one is called a semi-prime number if it can be decompounded to TWO prime numbers. For example, 6 is a semi-prime number but 12 is not.
Your task is just to determinate whether a given number is a semi-prime number.
Input
There are several test cases in the input. Each case contains a single integer N (2 <= N <= 1,000,000)
Output
One line with a single integer for each case. If the number is a semi-prime number, then output "Yes", otherwise "No".
Sample Input
3
4
6
12
Sample Output
No
Yes
Yes
No
好吧 我觉得我英语实在是要提升了!!!我了个去!!!这句话it can be decompounded to TWO prime numbers我把它理解为可以弄成两个素数的和了!!!然后就考虑打表去做,然后一直数据量太大!时间好长,然后我就弄出来这种理解的做法了,输进12,刺眼的YES!!居然样例都过不了。。。我开始审查我的代码了。。。开始想
为啥12过不了。。。不对,按我的想法,12=5+7。。这不俩素数嘛!!!我晕。。。开始仔细看题。。。这个单词实在不知道是啥。。。但是既然不是加。。。那就是乘了!!乘的话就水多了,直接求有多少个质因子,如果只有两个,那就YES。。。。
Time Limit: 2 Seconds Memory Limit: 65536 KB
Prime Number Definition
An integer greater than one is called a prime number if its only positive divisors (factors) are one and itself. For instance, 2, 11, 67, 89 are prime numbers but 8, 20, 27 are not.
Semi-Prime Number Definition
An integer greater than one is called a semi-prime number if it can be decompounded to TWO prime numbers. For example, 6 is a semi-prime number but 12 is not.
Your task is just to determinate whether a given number is a semi-prime number.
Input
There are several test cases in the input. Each case contains a single integer N (2 <= N <= 1,000,000)
Output
One line with a single integer for each case. If the number is a semi-prime number, then output "Yes", otherwise "No".
Sample Input
3
4
6
12
Sample Output
No
Yes
Yes
No
好吧 我觉得我英语实在是要提升了!!!我了个去!!!这句话it can be decompounded to TWO prime numbers我把它理解为可以弄成两个素数的和了!!!然后就考虑打表去做,然后一直数据量太大!时间好长,然后我就弄出来这种理解的做法了,输进12,刺眼的YES!!居然样例都过不了。。。我开始审查我的代码了。。。开始想
为啥12过不了。。。不对,按我的想法,12=5+7。。这不俩素数嘛!!!我晕。。。开始仔细看题。。。这个单词实在不知道是啥。。。但是既然不是加。。。那就是乘了!!乘的话就水多了,直接求有多少个质因子,如果只有两个,那就YES。。。。
#include <cstdio> using namespace std; int prim[1000002]; void pri() { prim[0] = prim[1] = 0; for (int i = 2; i <= 1000000; i++) prim[i] = i; for (int i = 2; i < 500000; i++){ if (prim[i]){ for (int j = 2; j * i <= 1000000; j++){ prim[j * i] = 0; } } } } int main() { int n, i, q; pri(); while (scanf("%d", &n) != EOF){ i = 0; q = 0; while (n != 1){ if (prim[i]){ while (n % prim[i] == 0){ n = n / prim[i]; q++; } } i++; } if (q == 2) printf("Yes\n"); else printf("No\n"); } return 0; }
相关文章推荐
- java虚拟机 jvm 出入java栈 栈空间内存分配
- 计时器编程实例
- 编写一个类似记事本的菜单
- Android_Studio_Checkout_Github_Error"Cannot run program "git.exe":CreateProcess error = 2
- 用双缓冲区实现对Frame的重载
- who|sort实现
- 在Frame画图应用
- 进程间的通信——无名管道
- 在Frame中对Graphics类的应用
- 在Frame对窗口进行重绘
- 对enableEvents类的应用
- 装修过程中的经典工序流程图(三)
- (OK) Linux epoll模型—socket epoll server client chat
- 实现单击“ok”按钮关闭窗口
- Combobox下拉框两级联动
- ubuntu――LAMP(Linux -3.13.0-32-generic ,Apache-2.4.18,MySQL-5.6.27,PHP -7.0.5)(二)
- Linux 命令 总结
- 用事件适配器来实现窗口的关闭
- Qt中读写xml文件
- 对WindowListener接口的简单应用