#include <iostream>
#include <math.h>
int prime(int);
using namespace std;
int main(){
int a ;
while(cin>>a)
{
int num = 0, base = 1 , b = a ;
while(1) //create new num
{
num = num *10 ;
num += (b % 10) * base ;
b = b / 10 ;
if(b == 0)
break;
}
int checkprime = prime(a) , checknumprime = prime(num);
if(checkprime == 0 && checknumprime == 0 && a!=num)
cout<<a<<" is emirp."<<endl;
else if(checkprime == 1 && checknumprime != 0 && a!=num)
cout<<a<<" is not prime."<<endl;
else if(checkprime == 0 && checknumprime != 0 && a != num)
cout<<a<<" is prime."<<endl;
else if(checkprime ==0 && checknumprime==0 && a==num)
cout<<a<<" is prime."<<endl;
}
return 0;
}
int prime(int x){
int time = 0 , root = sqrt(x) , i;
for(i=2;i<=root;i++)
{
int m = x % i ;
if(m == 0)
{
time++;
break;
}
}
return time ;
}
根據code 裡面出現應該是正確輸入的 數字才對
在自己這邊已經測試過132683 跟 91361這2比測資 正確 可是 不知道丟上去後為甚麼會出現
第 1 測資點(100%): WA (line:13)
答案不正確
您的答案為: 132683 is not prime. 正確答案為: 91361 is not prime.
#include
#include
int prime(int);
using namespace std;
int main(){
int a ;
while(cin>>a)
{
int num = 0, base = 1 , b = a ;
while(1) //create new num
{
num = num *10 ;
num += (b % 10) * base ;
b = b / 10 ;
if(b == 0)
break;
}
int checkprime = prime(a) , checknumprime = prime(num);
if(checkprime == 0 && checknumprime == 0 && a!=num)
cout<<a<<" is emirp."<<endl;
else if(checkprime == 1 && checknumprime != 0 && a!=num)
cout<<a<<" is not prime."<<endl;
else if(checkprime == 0 && checknumprime != 0 && a != num)
cout<<a<<" is prime."<<endl;
else if(checkprime ==0 && checknumprime==0 && a==num)
cout<<a<<" is prime."<<endl;
}
return 0;
}
int prime(int x){
int time = 0 , root = sqrt(x) , i;
for(i=2;i<=root;i++)
{
int m = x % i ;
if(m == 0)
{
time++;
break;
}
}
return time ;
}
根據code 裡面出現應該是正確輸入的 數字才對
在自己這邊已經測試過132683 跟 91361這2比測資 正確 可是 不知道丟上去後為甚麼會出現
第 1 測資點(100%): WA (line:13)
答案不正確
您的答案為: 132683 is not prime. 正確答案為: 91361 is not prime.
把篩選條件從
如果兩數都不是prime就輸出is not prime.,改成如果倒轉前的數字不是prime就輸出is not prime.