当前位置: 首页> 财经> 产业 > 网页设计培训的课程_南通外贸网站推广_百度移动开放平台_seo关键词优化的技巧和方法

网页设计培训的课程_南通外贸网站推广_百度移动开放平台_seo关键词优化的技巧和方法

时间:2025/8/23 12:34:59来源:https://blog.csdn.net/m0_75262437/article/details/146712750 浏览次数:1次
网页设计培训的课程_南通外贸网站推广_百度移动开放平台_seo关键词优化的技巧和方法

1015 Reversible Primes
分数 20

全屏浏览

切换布局
作者 CHEN, Yue
单位 浙江大学
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 (<10 
5
 ) 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

1.分析

        1.要判断原数是否是素数,还要判断反转后的数是否为素数

2.代码

#include<iostream>
#include<cmath>
using namespace std;
const int MAX=1e6+10;
int N,D,re[MAX];
bool check(int x){           //判断是否为素数for(int i=2;i<=x/i;i++){if(x%i==0) return false;}return true;
}
int main(){while(cin>>N){if(N<0) break;        //判断输入结束else cin>>D;if(N<2||!check(N)) {       //判断原数cout<<"No"<<endl;continue;}int num=0;while(N){                   //反转re[num++]=N%D;N/=D;}for(int i=num-1;i>=0;i--){N+=pow(D,num-i-1)*re[i];}if(N>=2&&check(N)) cout<<"Yes"<<endl;      //判断else cout<<"No"<<endl;}return 0;
}

关键字:网页设计培训的课程_南通外贸网站推广_百度移动开放平台_seo关键词优化的技巧和方法

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: