mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
41 lines
712 B
C++
41 lines
712 B
C++
|
#include<iostream>
|
||
|
#include<cstring>
|
||
|
#include<cstdio>
|
||
|
#include<math.h>
|
||
|
#include<algorithm>
|
||
|
using namespace std;
|
||
|
bool isPrimeNum(int num)
|
||
|
{
|
||
|
if (num <= 2)
|
||
|
{
|
||
|
return num == 2;
|
||
|
}
|
||
|
if (num % 2 == 0)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
int iSqrt = sqrt(num);
|
||
|
for (int i = 3; i <= iSqrt; i+=2)
|
||
|
{
|
||
|
if (num % i == 0)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
int main()
|
||
|
{
|
||
|
int t;
|
||
|
scanf("%d",&t);
|
||
|
while(t--)
|
||
|
{
|
||
|
int n;
|
||
|
scanf("%d",&n);
|
||
|
if(n==4) printf("2\n");
|
||
|
else if(isPrimeNum(n)) printf("%d\n",n-1);
|
||
|
else printf("0\n");
|
||
|
}
|
||
|
return 0;
|
||
|
}
|