描述

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. Mysql 常用函数(7)- length 函数

    Mysql常用函数的汇总,可看下面系列文章 https://www.cnblogs.com/poloyy/category/1765164.html length 的作用 返回字符串的字节长度 注意: ...

  2. 数据库中取出YYYY-mm-dd H:i:s的数据怎么将其转化成YYYY/mm/dd格式,另外,怎么将一个数据表中的数据插入另一个数据表

    sql语句是select  left(replace(rq,'-','/'),10) as rq from 表名 tp5.1中的写法 $res = Db::table('表名') ->field ...

  3. ql的python学习之路-day2

    python中所有字符串操作 , )))), ))))#返回50个长度的字符串,不够左边就以0补充,可以用在十六进制补位(不常用)运行结果: My name is qinjiaxi---------- ...

  4. urllib全解

    Urllib库的基本使用 转载1 博客园  python修行路:https://www.cnblogs.com/zhaof/p/6910871.html 转载2csdn          原文链接:h ...

  5. Git基本操作命令合集

    平时自己敲敲代码,使用Git命令也渐渐多了起来.使用起来的确很方便,今天来分享下Git基本概念和本地代码提交到github上的过程,很简单的,多操作几次就会了. Git定义 Git 是一个开源的分布式 ...

  6. Alink漫谈(四) : 模型的来龙去脉

    Alink漫谈(四) : 模型的来龙去脉 目录 Alink漫谈(四) : 模型的来龙去脉 0x00 摘要 0x01 模型 1.1 模型包含内容 1.2 Alink的模型文件 0x02 流程图 0x03 ...

  7. .Net基础之3——运算符

    (3)Convert类型转换 1.类型如果相兼容的两个变量,可以使用自动类型转换或者显示类型转换. 但是如果两个类型的变量不兼容,这个时候可以使用一个叫做Convert的转换工厂进行转换. 注意:使用 ...

  8. 解决iframe重定向让父级页面跳转

    原文:http://www.jb51.net/article/40583.htm 有内嵌iframe的页面,当session过期时,点击连接重定向后的跳转会在iframe中跳转,在登录页面中加入下面的 ...

  9. docker 日志查看与清洗

    Linux下查看磁盘与目录的容量——df.du df:列出文件系统的整体磁盘使用量: du:评估文件系统的磁盘使用量(常用于评估目录所占容量) df参数: -a:列出所有的文件系统,包括系统特有的/p ...

  10. python中几个双下划线用法的含义

    _ _ init() _ _(self[,...]) 我们有时在类定义写__init()__方法,但是有时又没有.__init()__方法相当于其他面向对象的编程语言中的构造方法,也就是类在实例化成对 ...