描述

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.

输入

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.

输出

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

样例输入

73 10

23 2

23 10

-2

样例输出

Yes

Yes

No

判断素数和数制转换

#include <stdio.h>
#include <math.h>
int prime(int n)
{
int i,j=sqrt(n);
for(i=;i<=j;i++)
{
if(n%i==)
return ;
}
return ;
}
int ss(int n,int m)
{
int i=,s=,h,a[]={};
while(n)
{
a[i]=n%m;
n/=m;
i++;
}
for(h=;h<=i-;h++)
{
s=s*m+a[h];
}
return s;
}
int main()
{
int n,m,i;
while(scanf("%d",&n),n>)
{
scanf("%d",&m);
if(prime(n)==&&prime(ss(n,m))==)
{
printf("Yes\n");
}
else printf("No\n");
}
return ;
}

PAT甲级 Reversible Primes的更多相关文章

  1. PAT 1015 Reversible Primes

    1015 Reversible Primes (20 分)   A reversible prime in any number system is a prime whose "rever ...

  2. PAT 1015 Reversible Primes[求d进制下的逆][简单]

    1015 Reversible Primes (20)(20 分)提问 A reversible prime in any number system is a prime whose "r ...

  3. pat 1015 Reversible Primes(20 分)

    1015 Reversible Primes(20 分) A reversible prime in any number system is a prime whose "reverse& ...

  4. PAT A1015 Reversible Primes (20 分)——进制转换,质数

    A reversible prime in any number system is a prime whose "reverse" in that number system i ...

  5. PAT 1015 Reversible Primes (判断素数)

    A reversible prime in any number system is a prime whose "reverse" in that number system i ...

  6. PAT 1015 Reversible Primes (20分) 谜一般的题目,不就是个进制转换+素数判断

    题目 A reversible prime in any number system is a prime whose "reverse" in that number syste ...

  7. PAT_A1015#Reversible Primes

    Source: PAT A1015 Reversible Primes (20 分) Description: A reversible prime in any number system is a ...

  8. PAT 甲级 1015 Reversible Primes(20)

    1015 Reversible Primes(20 分) A reversible prime in any number system is a prime whose "reverse& ...

  9. PAT 甲级 1015 Reversible Primes (20 分) (进制转换和素数判断(错因为忘了=))

    1015 Reversible Primes (20 分)   A reversible prime in any number system is a prime whose "rever ...

随机推荐

  1. 搭建私有镜像仓库registry 2.0

    搭建 docker run -d -p 5000:5000 --restart=always --name registry2 registry:2 就可以将自己的镜像 push到这个私有的镜像仓库 ...

  2. 关于tez-ui的"All DAGs"和"Hive Queries"页面信息为空的问题解决过程

    近段时间发现公司的HDP大数据平台的tez-ui页面不能用了,页面显示为空,导致通过hive提交的sql不能方便地查找到Yarn上对应的applicationId,只能通过beeline的屏幕输出信息 ...

  3. 2018-06-21 js正则表达式

    正则表达式:描述了一种字符串匹配的模式,可以用来检查一个串是否含有某种子串.将匹配的子串替换或者从某个串中取出符合某个条件的子串等. 1.修饰符 i->忽略大小写: g->全部匹配: m- ...

  4. webpack从零的实践(新手良药)

    1. 什么是webpack? 本质上,webpack是一个现代javascript应用程序的静态模块打包器.webpack处理应用程序时,它会递归地构建一个依赖关系图(dependency graph ...

  5. 小程序使用模板template

    小程序使用模板template 1.介绍:模板就是代码的高度复用,将在很多页面使用了相同的部分可以使用模板封装 <!-- 在页面组件中使用 --> <!-- 此时定义了一个模板 -- ...

  6. 蒲公英 · JELLY技术周刊 Vol.07: EcmaScript 2020 -- 所有你想要知道的都在这

    「蒲公英」期刊,每周更新,我们专注于挖掘「基础技术.工程化.跨端框架技术.图形编程.服务端开发.桌面开发.人工智能」等多个大方向的业界热点,并加以专业的解读:不仅如此,我们还精选凹凸技术文章,向大家呈 ...

  7. jQuery的面试题

    1.$的原理 答案: 1)$("选择器")是先查找DOM元素,再将DOM元素放入jQuery对象中 其中自带优化: 如果选择器是#id,则自动调用getElementById 如果 ...

  8. iframe中请求页面而session失效时页面跳转问题

    iframe中请求页面而session失效时页面跳转问题 分类: Web2009-12-11 15:01 656人阅读 评论(0) 收藏 举报 sessioniframejsp 有时候做了就忘了,我记 ...

  9. logback如何配置springboot框架

    创建logback-spring.xm在src/main/resources下面(springboot推荐使用logback-spring.xml而不是logback.xml)文件. logback- ...

  10. Flask开发技巧之异常处理

    Flask开发技巧之异常处理 目录 Flask开发技巧之异常处理 1.Flask内置异常处理 2.HTTPException类分析 3.自定义异常处理类 4.方便的定义自己的错误类 5.注意事项 本人 ...