R

Description

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 

题意:

判断是否是半素数,半素数就是两个素数的乘积

分析:

先找出1000以前的素数,然后判断n/素数是否为素数

代码:

#include<bits/stdc++.h>
using namespace std;
int vp(long int n)
{
    int i,f;
    for(i=2,f=0;i<=sqrt(n);i++)
        if(n%i==0)
            {
                f=1;
                break;
            }
    if(f)
        return 0;
    else
       return 1;
}
int main()
{
    long int i,n,k,a[1500],f,t;
    for(i=2,t=0;i<1000;i++)
        if(vp(i)){
           a[t]=i;
           t++;
        }
    while(cin>>n)
    {
        for(i=0,f=0;i<t;i++){
            if(n%a[i]==0&&vp(n/a[i])&&n>a[i])
            {
                f=1;
                break;
            }
            if(n<=a[i])
                break;
        }

        if(f)
            cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;
    }
}

感觉:

我感觉我的方法有点粗暴。。不太好闭嘴

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值