代码
//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.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//decide n whither is a nearly prime number or not,
//is then return true,or return false.
bool isNPN(int n);
//decide n whither is a prime number or not,
//is then return true,or return false.
bool isPrime(int n);
int main()
{
int input[50000];
int num;
//input
scanf("%d", &num);
for (int i=0; i<num; i++)
{
scanf("%d", &input[i]);
}
//start resolve the problem here
for (int i=0; i<num; i++)
{
if (isNPN(input[i]))
{
printf("Yes\n");
}
else
{
printf("No\n");
}
}
return 0;
}
bool isNPN(int n)
{
int m = (int)sqrt((double)n) + 1;
if (n%2==0 && isPrime(n/2))
{
return true;
}
for (int i=3; i<m; i+=2)
{
if (n%i == 0 && isPrime(i))
{
if (isPrime(n/i))
{
return true;
}
}
}
return false;
}
bool isPrime(int n)
{
int m = (int)sqrt((double)n) + 1;
if (n == 2)
{
return true;
}
if (n%2 == 0)
{
return false;
}
for(int i=3; i<m; i+=2)
{
if (n%i==0)
{
return false;
}
}
return true;
}
//to find such primes P1 and P2 that given number is equal to P1*P2.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//decide n whither is a nearly prime number or not,
//is then return true,or return false.
bool isNPN(int n);
//decide n whither is a prime number or not,
//is then return true,or return false.
bool isPrime(int n);
int main()
{
int input[50000];
int num;
//input
scanf("%d", &num);
for (int i=0; i<num; i++)
{
scanf("%d", &input[i]);
}
//start resolve the problem here
for (int i=0; i<num; i++)
{
if (isNPN(input[i]))
{
printf("Yes\n");
}
else
{
printf("No\n");
}
}
return 0;
}
bool isNPN(int n)
{
int m = (int)sqrt((double)n) + 1;
if (n%2==0 && isPrime(n/2))
{
return true;
}
for (int i=3; i<m; i+=2)
{
if (n%i == 0 && isPrime(i))
{
if (isPrime(n/i))
{
return true;
}
}
}
return false;
}
bool isPrime(int n)
{
int m = (int)sqrt((double)n) + 1;
if (n == 2)
{
return true;
}
if (n%2 == 0)
{
return false;
}
for(int i=3; i<m; i+=2)
{
if (n%i==0)
{
return false;
}
}
return true;
}