[ZJ]b513: 判斷質數-商競103
題目:
http://zerojudge.tw/ShowProblem?problemid=b513
--------------------------------------------------------------------------------------------
#include<cstdio>
#include<cmath>
int isprime(int n)
{
if(n == 2)
return 1;
int x = 2, flag = 1;
while(x <= sqrt(n))
{
if(!(n%x))
{
flag = 0;
break;
}
x++;
}
return flag;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
printf("%c\n",isprime(n)?'Y':'N');
}
return 0;
}
http://zerojudge.tw/ShowProblem?problemid=b513
--------------------------------------------------------------------------------------------
#include<cstdio>
#include<cmath>
int isprime(int n)
{
if(n == 2)
return 1;
int x = 2, flag = 1;
while(x <= sqrt(n))
{
if(!(n%x))
{
flag = 0;
break;
}
x++;
}
return flag;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
printf("%c\n",isprime(n)?'Y':'N');
}
return 0;
}
留言
張貼留言