View Code
#include < iostream >
#include < cstring >
using namespace std;
typedef long long ll;
int p[ 100001 ] , tem[ 100001 ] ,t;
void Init()
{
memset(p, 0 , sizeof (p));
for (ll i = 2 ; i <= 100000 ; i ++ )
{
if ( ! p[i] )
{
for ( ll j = 2 ; j * i <= 100000 ; j ++ )
p[j * i] = 1 ;
}
}
t = 0 ;
for ( int i = 2 ;i < 1000000 ;i ++ )
{
if ( ! p[i])
{
tem[t ++ ] = i;
}
}
}
void Prime(ll n)
{
for ( int i = 0 ; i < t && tem[i] < n; i ++ )
{
if (n % tem[i] == 0 )
{`
cout << " YES " << endl;
return ;
}
}
cout << " NO " << endl;
}
int main()
{
ll n;
Init();
while (cin >> n)
{
if (n == 1 ) cout << " YES " << endl;
else if (n == 4 ) cout << " NO " << endl;
else Prime(n);
}
return 0 ;
}
转载于:https://my.oschina.net/garyun/blog/602844