当前位置:网站首页>1015 reversible primes (20 points) prime d-ary

1015 reversible primes (20 points) prime d-ary

2022-07-06 07:27:00 Python ml

#include <iostream>
using namespace std;
bool isprime(int a){
    
    if(a==1)return false;
    for(int i=2;i*i<=a;i++)
        if(a%i==0)return false;
    return true;
}
int main() {
       
    int n,d;
    while (scanf("%d",&n)!=EOF){
    
        if(n<0)break;
        scanf("%d",&d);
        if(isprime(n)==false){
    
            printf("No\n");
            continue;
        }
        int len=0,arr[100];
        do{
                                 // Convert to d Base number 
            arr[len++]=n%d;
            n=n/d;
        }while(n>0);
        for(int i=0;i<len;i++)            // Calculation d The corresponding 10 Whether the hexadecimal number is a prime number 
            n=n*d+arr[i];
        printf("%s\n", isprime(n) ? "Yes" : "No");
    }
    return 0;
}
原网站

版权声明
本文为[Python ml]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131923181819.html