1. 题目

2. 抽象建模

3. 方法

4. 注意点

  1. 素数判断(1不是素数)
  2. 数值的倒转

5. 代码

  1. #include<stdio.h>
  2. #include<math.h>
  3. int isPrime(int num){
  4. if(num < 2){
  5. return 0;
  6. }
  7. for(int i=2;i<=num/2;i++){
  8. if(num%i == 0){
  9. return 0;
  10. }
  11. }
  12. return 1;
  13. }
  14. int reverse(int num, int d, int &count){
  15. if(num < d){
  16. return num*pow(d, count++);
  17. }else{
  18. return reverse(num/d, d, count) + (num%d)*pow(d, count++);
  19. }
  20. }
  21. int main(){
  22. int order = 0;
  23. int num, d;
  24. while(1){
  25. order = 0;
  26. scanf("%d", &num);
  27. if(num < 0){
  28. break;
  29. }
  30. scanf("%d", &d);
  31. if(isPrime(num) && isPrime(reverse(num, d, order))){
  32. printf("Yes\n");
  33. }else{
  34. printf("No\n");
  35. }
  36. }
  37. return 0;
  38. }

1015 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(20)

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

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

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

  4. pat 1015 Reversible Primes(20 分)

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

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

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

  6. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any n ...

  7. PTA (Advanced Level) 1015 Reversible Primes

    Reversible Primes A reversible prime in any number system is a prime whose "reverse" in th ...

  8. 1015. Reversible Primes (20)

    the problem is from PAT,which website is http://pat.zju.edu.cn/contests/pat-a-practise/1015 this pro ...

  9. 1015 Reversible Primes (20)(20 point(s))

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

  10. PAT 甲级 1015 Reversible Primes

    https://pintia.cn/problem-sets/994805342720868352/problems/994805495863296000 A reversible prime in ...

随机推荐

  1. json转义处理

    php把参数转成json字符串,中文会变成unicode,有部分会自动转义(添加反斜杠\) json_encode() #中文不转义对应的数字 256) json_encode($data,JSON_ ...

  2. 杜教筛BM

    #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> # ...

  3. AMCL论文及源码解析--参数(持续更新中)

    整理内容来自:http://wiki.ros.org/amcl 1.AMCL订阅的节点: scan (sensor_msgs/LaserScan):激光数据 tf (tf/tfMessage):各种转 ...

  4. 题解 AT4278 【[ABC115A] Christmas Eve Eve Eve】

    题目传送门. 分析 根据题目,我们可以发现要求如下: \(d\)的值 输出 \(d=25\) Christmas \(d=24\) Christmas Eve \(d=23\) Christmas E ...

  5. list类型的应用场景 —— Redis实战经验

    list类型是简单的字符串列表,按照插入顺序排序.每个列表最多可以存储 232 - 1 个元素(40多亿) ,list类型主要有以下应用场景.. 1. 消息队列 list类型的lpop和rpush(或 ...

  6. Git和TortoiseGit

    1.简介 Git是一个开源的分布式版本控制系统,用于敏捷高效的处理任何或大或小的项目.它采用了分布式版本库的方式,不必服务器端软件支持. 2.Git和Svn的区别 1.Git 是分布式的,SVN 不是 ...

  7. ubuntu python 安装使用虚拟环境 virtualenv

    1,虚拟环境是干啥用的? 我在电脑上装了cuda,显卡驱动,cudnn等一堆配套文件,然后又依赖于cuda和驱动安装了tensorflow2.0的gpu测试版,不知为何,我每次跑完tf2程序电脑都会卡 ...

  8. 深入理解IP之CIDR

    现代IP基于分类的IP越来越少,而基于CIDR的方式的越来越多.那么可以看下面这篇文章: https://www.cnblogs.com/hark0623/p/6547432.html 这篇文章对CI ...

  9. 梯度下降算法&线性回归算法

    **机器学习的过程说白了就是让我们编写一个函数使得costfunction最小,并且此时的参数值就是最佳参数值. 定义 假设存在一个代价函数 fun:\(J\left(\theta_{0}, \the ...

  10. 假期学习【四】RDD编程实验一

    1.今天把Spark编程第三个实验的Scala独立程序编程写完了.使用 sbt 打包 Scala 程序,然后提交到Spark运行. 2.完成了实验四的第一项 (1)该系总共有多少学生:   map(t ...