您的位置:首页 > 科技 > 能源 > 长沙网络营销学校_免费永久vps服务器_seo关键词排名点击工具_企业宣传推广

长沙网络营销学校_免费永久vps服务器_seo关键词排名点击工具_企业宣传推广

2024/11/17 14:54:23 来源:https://blog.csdn.net/2401_88085478/article/details/143050710  浏览:    关键词:长沙网络营销学校_免费永久vps服务器_seo关键词排名点击工具_企业宣传推广
长沙网络营销学校_免费永久vps服务器_seo关键词排名点击工具_企业宣传推广

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

题目大意:如果一个数本身是素数,而且在d进制下反转后的数在十进制下也是素数,就输出Yes,否则就输出No

#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <cstdio>
#include    <ctime>
#include    <cmath>
#define ll long long
#define INF 0x3f3f3f3f
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
#define db4(x,y,z,r) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<endl
using namespace std;int prime[100010]={1,1};
void getprime()
{for(int i=2;i*i<=100000;i++)if(!prime[i])for(int j=i;j*i<=100000;j++)prime[j*i]=1;
}int main(void)
{#ifdef testfreopen("in.txt","r",stdin);//freopen("in.txt","w",stdout);clock_t start=clock();#endif //testgetprime();int n;while(scanf("%d",&n),n>=0){int d;scanf("%d",&d);if(prime[n]==1){printf("No\n");continue;}int cnt[100000]={0},t=0;do{cnt[t++]=n%d,n/=d;}while(n!=0);int num=0;for(int i=0;i<t;++i)num=num*d+cnt[i];if(prime[num])printf("No\n");else printf("Yes\n");}#ifdef testclockid_t end=clock();double endtime=(double)(end-start)/CLOCKS_PER_SEC;printf("\n\n\n\n\n");cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位#endif //testreturn 0;
}

版权声明:

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

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