描述

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. JUC(3)---CountDownLatch、CyclicBarrier和AQS

    CountDownLatch可以让一个线程等待其他线程完成了各自的工作之后再执行.比如说一个切菜,一个人切肉,都准备完毕之后才能炒肉. 构造方法: public CountDownLatch(int ...

  2. Cannot parse "1986-05-04": Illegal instant due to time zone offset transition (Asia/Shanghai)

    调查系统错误时,发现了一个很奇怪的现象,出生日期1986-05-04号的用户始终无法注册.发现后台使用使用jodatime的代码demo如下: public static DateTime parse ...

  3. Spring Boot 之 Spring Batch 批处理实践

    实践内容 从 MariaDB 一张表内读 10 万条记录,经处理后写到 MongoDB . 具体实现 1.新建 Spring Boot 应用,依赖如下: <!-- Web 应用 --> & ...

  4. 在终端输入npm run serve时出现npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! test_vue_0613@1.0.0 dev: 错误的解决方法

    在vscode终端使用命令 npm run serve 的时候报错 错误原因在于由于文件 node_modules 太大,在项目上传时有些人会删掉 导致我们下载的项目中缺少这个文件 在尝试把自己项目的 ...

  5. mysql 审计server_audit 模块

    server_audit模块是一个 mariadb  还是skysql 开发的一个mysql 的插件.可以做一些审计上面的工作. 众所周知,mysql 是里面是很难记录用户的操作命令的.用这个就可以. ...

  6. .net core BundlerMinifier.BundlerBuildTask 任务意外失败

    BundlerMinifier.BundlerBuildTask : 捆绑和缩小CSS.JS和HTML文件 BundlerMinifier.BundlerBuildTask 任务意外失败处理: 1.在 ...

  7. mysql运维入门4:索引、慢查询、优化

    MySQL索引用来快速地寻找那些具有特定值的记录,所有MySQL索引都是以B-树的形式保存 如果没有索引,执行查询时,MySQL必须从第一个记录开始整表扫描,知道查询到符合要求的记录,记录越大,花费时 ...

  8. javaWeb普通类获取ApplicationContext

    网上看了很多关于获取ApplicationContext的方法,五大方法,但是我用web服务使用成功的就这一个,自己记忆下. import javax.servlet.ServletContextEv ...

  9. Word与Excel中,如何输入✔标志

    为了表达值的对错,或者相关任务是否完成,我们需要在word及excel中输入[√]和[x] Word与Excel中如何在方框“口”中打勾[√]和[x],在Word中打钩的方法有3种:第一种,在插入特殊 ...

  10. 为什么说OC是运行时语言?什么是动态类型、动态绑定、动态加载?

    转载:https://www.cnblogs.com/dxb123456/p/5525343.html 动态: 主要是将数据类型的确定由编译时,推迟到了运行时. 这个问题其实浅涉及到两个概念,运行时和 ...