标签:names stream 代码 scanf i++ for return -- code
int len = 0;
do{
d[len++] = n % radix;//转化成该进制,数组低位表示转换后进制的低位;
n /= radix;
}while(n != 0);
int p = 1;
for(int i = len - 1; i >= 0; i--){
n = n + d[i] * p;//逆序后按原来进制转化为10进制;
p = p * radix;
}
#include<iostream>
#include<cmath>
using namespace std;
bool isPrime(int x){
if(x <= 1) return false;
int sqr = (int)sqrt(x);
for(int i = 2; i <= sqr; i++){
if(x % i == 0) return false;
}
return true;
}
int d[111];
int main(){
int n, radix;
while(scanf("%d", &n) != EOF){
if(n < 0) break;
scanf("%d", &radix);
if(isPrime(n) == false){
printf("No\n");
}else{//进制转换
int len = 0;
do{
d[len++] = n % radix;
n /= radix;
}while(n != 0);
int p = 1;
for(int i = len-1; i >= 0; i--){
n = n + d[i] * p;
p = p * radix;
}
if(isPrime(n) == true) printf("Yes\n");
else printf("No\n");
}
}
return 0;
}
A1015 Reversible Primes (20分)(素数判断,进制转换)
标签:names stream 代码 scanf i++ for return -- code
原文地址:https://www.cnblogs.com/tsruixi/p/13215998.html