1015 Reversible Primes
1. 题目
2. 抽象建模
无
3. 方法
无
4. 注意点
- 素数判断(1不是素数)
- 数值的倒转
5. 代码
#include<stdio.h>
#include<math.h>
int isPrime(int num){
if(num < 2){
return 0;
}
for(int i=2;i<=num/2;i++){
if(num%i == 0){
return 0;
}
}
return 1;
}
int reverse(int num, int d, int &count){
if(num < d){
return num*pow(d, count++);
}else{
return reverse(num/d, d, count) + (num%d)*pow(d, count++);
}
}
int main(){
int order = 0;
int num, d;
while(1){
order = 0;
scanf("%d", &num);
if(num < 0){
break;
}
scanf("%d", &d);
if(isPrime(num) && isPrime(reverse(num, d, order))){
printf("Yes\n");
}else{
printf("No\n");
}
}
return 0;
}
1015 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(20)
1015 Reversible Primes(20 分) A reversible prime in any number system is a prime whose "reverse& ...
- 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 甲级 1015 Reversible Primes (20 分) (进制转换和素数判断(错因为忘了=))
1015 Reversible Primes (20 分) A reversible prime in any number system is a prime whose "rever ...
- PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642
PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any n ...
- PTA (Advanced Level) 1015 Reversible Primes
Reversible Primes A reversible prime in any number system is a prime whose "reverse" in th ...
- 1015. Reversible Primes (20)
the problem is from PAT,which website is http://pat.zju.edu.cn/contests/pat-a-practise/1015 this pro ...
- 1015 Reversible Primes (20)(20 point(s))
problem A reversible prime in any number system is a prime whose "reverse" in that number ...
- PAT 甲级 1015 Reversible Primes
https://pintia.cn/problem-sets/994805342720868352/problems/994805495863296000 A reversible prime in ...
随机推荐
- json转义处理
php把参数转成json字符串,中文会变成unicode,有部分会自动转义(添加反斜杠\) json_encode() #中文不转义对应的数字 256) json_encode($data,JSON_ ...
- 杜教筛BM
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> # ...
- AMCL论文及源码解析--参数(持续更新中)
整理内容来自:http://wiki.ros.org/amcl 1.AMCL订阅的节点: scan (sensor_msgs/LaserScan):激光数据 tf (tf/tfMessage):各种转 ...
- 题解 AT4278 【[ABC115A] Christmas Eve Eve Eve】
题目传送门. 分析 根据题目,我们可以发现要求如下: \(d\)的值 输出 \(d=25\) Christmas \(d=24\) Christmas Eve \(d=23\) Christmas E ...
- list类型的应用场景 —— Redis实战经验
list类型是简单的字符串列表,按照插入顺序排序.每个列表最多可以存储 232 - 1 个元素(40多亿) ,list类型主要有以下应用场景.. 1. 消息队列 list类型的lpop和rpush(或 ...
- Git和TortoiseGit
1.简介 Git是一个开源的分布式版本控制系统,用于敏捷高效的处理任何或大或小的项目.它采用了分布式版本库的方式,不必服务器端软件支持. 2.Git和Svn的区别 1.Git 是分布式的,SVN 不是 ...
- ubuntu python 安装使用虚拟环境 virtualenv
1,虚拟环境是干啥用的? 我在电脑上装了cuda,显卡驱动,cudnn等一堆配套文件,然后又依赖于cuda和驱动安装了tensorflow2.0的gpu测试版,不知为何,我每次跑完tf2程序电脑都会卡 ...
- 深入理解IP之CIDR
现代IP基于分类的IP越来越少,而基于CIDR的方式的越来越多.那么可以看下面这篇文章: https://www.cnblogs.com/hark0623/p/6547432.html 这篇文章对CI ...
- 梯度下降算法&线性回归算法
**机器学习的过程说白了就是让我们编写一个函数使得costfunction最小,并且此时的参数值就是最佳参数值. 定义 假设存在一个代价函数 fun:\(J\left(\theta_{0}, \the ...
- 假期学习【四】RDD编程实验一
1.今天把Spark编程第三个实验的Scala独立程序编程写完了.使用 sbt 打包 Scala 程序,然后提交到Spark运行. 2.完成了实验四的第一项 (1)该系总共有多少学生: map(t ...