G. 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.
sphenic数字是三个不同质数的乘积。
帮助Vasya写一个程序来区分sphenic数字。
Examples
30
YES
40
NO
10467397
YES
#include <bits/stdc++.h>
using namespace std;
int get_num(int n)
{
int cnt = 0;
for (int i = 2; i <= sqrt((double)n); i++)
{
if (n % i == 0) {
cnt++;
}
while (n % i == 0) {
n = n / i;
}
}
if (n > 1) {
cnt++;
}
return cnt++;
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n;
while (cin >> n)
{
int flag = get_num(n);
if (flag == 3) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
return 0;
}