题目:
Nearly prime number is an integer positive number
for which it is possible to find such primes P1 and P2
that given number is equal to P1*P2.
There is given a sequence on N integer positive numbers,
you are to write a program that prints Yes
if given number is nearly prime and No otherwise.
这是我AC的代码,大家可以参考参考。
#include <iostream>
#include<cmath>
using namespace std;
int n;
long M;
void work(long cur)
{
int kind=0;
int temp=0,max=0;
for(int i=2;i*i<=cur;i++)
{
if(cur%i==0)
kind++;
temp=0;
while(cur%i==0)
{
cur/=i;
temp++;
}
if(temp>max)
max=temp;
}
if(cur>1)
{
kind++;
if(1>max)
max=1;
}
if( (kind==2&&max==1) || (kind==1&&max==2) )
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>M;
work(M);
}
return 0;
}