国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

1015. Reversible Primes (20)

2019-11-11 04:17:49
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

A reversible PRime in any number system is a prime whose “reverse” in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime.

Now given any two positive integers N (< 105) and D (1 < D <= 10), you are supposed to tell if N is a reversible prime with radix D.

Input Specification:

The input file consists of several test cases. Each case occupies a line which contains two integers N and D. The input is finished by a negative N.

Output Specification:

For each test case, print in one line “Yes” if N is a reversible prime with radix D, or “No” if not.

Sample Input: 73 10 23 2 23 10 -2 Sample Output: Yes Yes No

#include<cstdio>bool isPrime(int x){ bool flag=true; if(x==1){ flag=false; } for(int i=2;i*i<=x;i++){ if(x%i==0){ flag=false; break; } } return flag;}int num[110];int main(){ int n,d; while(scanf("%d",&n)!=EOF){ if(n<0) break; scanf("%d",&d); if(isPrime(n)==false){ printf("No/n"); }else{ int len=0; do{ num[len++]=n%d; n/=d; }while(n); int rev=0; for(int i=0;i<len;i++){ rev=rev*d+num[i]; } if(isPrime(rev)==true){ printf("Yes/n"); }else{ printf("No/n"); } } } return 0;}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 天台县| 中牟县| 永年县| 保定市| 屏东县| 古蔺县| 越西县| 金坛市| 广宁县| 丰原市| 肥城市| 灵石县| 班戈县| 施秉县| 银川市| 云和县| 皮山县| 敦化市| 砀山县| 涿州市| 威远县| 洪泽县| 汶川县| 伊金霍洛旗| 靖边县| 屏东县| 祥云县| 哈巴河县| 昌邑市| 文山县| 红安县| 彭州市| 琼结县| 通许县| 元朗区| 清远市| 屯昌县| 库尔勒市| 孟津县| 岱山县| 孟津县|