G. Sphenic numbers

AC代码(唯一分解定理)

Select Code

#include <iostream>
#include <bits/stdc++.h>
#define maxn 0x3f3f3f3f
using namespace std;
long long sm = 0;
int k,s[20000];
void w(long long n)
{
    k = 0;
    for(int i = 2;i<=n;i++)
    {
        if(n%i==0)
        {
            while(n%i==0)
            {
                n/=i;
                s[k++] = i;
            }
        }
    }
}
int main()
{

     freopen("INPUT.TXT", "r", stdin);
    freopen("OUTPUT.TXT","w",stdout);
    cin>>sm;
    w(sm);
    if(k==3)
    {
        if(s[2]!=s[1]&&s[1]!=s[0])
        {
            printf("YES\n");
        }
        else
            printf("NO\n");
    }
    else
        printf("NO\n");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41524782/article/details/81709994