Sphenic numbers(素数筛)

Schoolboy Vasya is interested in the problem of distinguishing prime numbers. He has decided to develop his own testing method for it. Unfortunately, the new algorithm has one deficiency – it yields false positive outputs in case with so-called sphenic numbers. For those who does not know: sphenic number is the product of exactly three distinct prime numbers. Help Vasya write a program to distinguish sphenic numbers.

Inut

The input file contains a single number – integer n.

Limitations

30 ≤ n ≤ 10467397.

Output

The output file must contain one single line with the value “YES” (without quotation marks) if number n is sphenic or “NO” if it is not. Examples

Examples

Input.txt

30

40

10467397 

 

Output.txt

YES

NO

YES

 

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <math.h>
 4 
 5 #define maxx 10467397/6
 6 
 7 int cur, prime[maxx+10];
 8 int vis[maxx+10];
 9 void find_prime()
10 {
11     int i, j;
12     memset(vis, 0, sizeof(vis));
13     cur = 0;
14     for(i=2; i<maxx; i++)
15     {
16         if(vis[i]==0)
17         {
18             prime[cur++] = i;
19             for(j=1; j*i<=maxx; j++)
20             {
21                 vis[j*i] = 1;
22             }
23         }
24 
25     }
26 }
27 
28 int solve(int n)
29 {
30     int num = 0, i;
31     for(i=0; i<cur&&n>1; i++)
32     {
33         if(n % prime[i]==0)
34         {
35             num++;
36             n/=prime[i];
37         }
38         if(n % prime[i]==0) break;
39     }  
40     if(num==3&&n==1&&!(i<cur&&n>1)) return 1;
41     else return 0;
42 }
43 
44 int main()
45 {
46     freopen("input.txt", "r", stdin);
47     freopen("output.txt", "w", stdout);
48     int n;
49     find_prime();
50     scanf("%d", &n);
51     if(solve(n)) printf("YES\n");
52     else printf("NO\n");
53     return 0;
54 }

 

转载于:https://www.cnblogs.com/0xiaoyu/p/11342504.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值