PAT甲级 Reversible Primes
描述
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的更多相关文章
- PAT 1015 Reversible Primes
1015 Reversible Primes (20 分) A reversible prime in any number system is a prime whose "rever ...
- PAT 1015 Reversible Primes[求d进制下的逆][简单]
1015 Reversible Primes (20)(20 分)提问 A reversible prime in any number system is a prime whose "r ...
- pat 1015 Reversible Primes(20 分)
1015 Reversible Primes(20 分) A reversible prime in any number system is a prime whose "reverse& ...
- PAT A1015 Reversible Primes (20 分)——进制转换,质数
A reversible prime in any number system is a prime whose "reverse" in that number system i ...
- PAT 1015 Reversible Primes (判断素数)
A reversible prime in any number system is a prime whose "reverse" in that number system i ...
- PAT 1015 Reversible Primes (20分) 谜一般的题目,不就是个进制转换+素数判断
题目 A reversible prime in any number system is a prime whose "reverse" in that number syste ...
- PAT_A1015#Reversible Primes
Source: PAT A1015 Reversible Primes (20 分) Description: A reversible prime in any number system is a ...
- PAT 甲级 1015 Reversible Primes(20)
1015 Reversible Primes(20 分) A reversible prime in any number system is a prime whose "reverse& ...
- PAT 甲级 1015 Reversible Primes (20 分) (进制转换和素数判断(错因为忘了=))
1015 Reversible Primes (20 分) A reversible prime in any number system is a prime whose "rever ...
随机推荐
- centos7 下安装apache mysql php phpmyadmin。
1 安装mysql yum -y install mariadb-server systemctl start mariadb.service systemctl enable mariadb.ser ...
- lrzsz-神一样的上传下载工具
yum list lrzsz rz sz filename
- 【雕爷学编程】零基础Python(01)---“投机取巧”的三条途径
从3月13日报名尝试上网课学习(4天课8.9元),开始接触Python(中文发音“派森”),到今天有一星期了.这两天广泛搜索了一下相关的学习途径,本着“投机取巧”的出发点,居然小有心得,这里一并分享出 ...
- 使用gitHub和git进行团队合作开发
1.创建仓库(项目)-----组织者(Leader)和团队成员 1)Leader在gitHub上创建一个新组织(New organization),然后邀请成员加入 2)Leader在该组织下创建一个 ...
- 终于明白了vue使用axios发送post请求时的坑及解决原理
前言:在做项目的时候正好同事碰到了这个问题,问为什么用axios在发送请求的时候没有成功,请求不到数据,反而是报错了,下图就是报错请求本尊 vue里代码如下: this.$http.post('/ge ...
- eclipse 整合mybatis的过程
一.下载mybatis和数据库驱动的jar,我这里用到的数据库是pgAdmin III ,所以我下载的jar包分别为mybatis-3.0.2 jar和po's'tgresql-42.2.1.jar, ...
- mysql小白系列_06 备份与恢复
1.使用mydumper工具全库备份. 1)源码编译安装 2)全库备份 2.误操作truncate table gyj_t1;利用mysqldump的备份和binlog日志对表gyj_t1做完全恢复. ...
- python3.x 基础六:面向对象
面向对象特性 class 类 一个类是对一类拥有相同属性的对象的描述,在类中定义了这些对象都具备的属性/共同方法 object对象 一个对象指一个类实例化后的实例,一个类必须经过实例化后才能在程序中调 ...
- docker常用命令,及进入Tomcat的WebApps发布目录(就是进入docker容器后台目录)
docker常用命令,及进入Tomcat的WebApps发布目录(就是进入docker容器后台目录) 一.常用命令 1.显示所有的容器,包括未运行的 docker ps -a 2.启动容器.注 ...
- 记一次 React Native 大版本升级过程——从0.40到0.59
去年把公司几个react native 相关的项目升级了下,已经过去一段时间了,这里系统整理下之前的整个过程. 背景 之前到公司的时候发现公司用的还是0.40的版本,据了解,当时项目做的比较早,导航用 ...