PAT 甲级【1015 Reversible Primes】
- 考察素数判断
- 考察进制转换
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer; public class Main {
@SuppressWarnings("uncheck")
public static void main(String[] args) throws IOException {
StreamTokenizer st = new StreamTokenizer(new InputStreamReader(System.in));
int n, d;
while (true) {
st.nextToken();
n = (int) st.nval;
if (n < 0) {
break;
}
st.nextToken();
d = (int) st.nval;
String str = Integer.toString(n, d);
String reversestr = new StringBuilder(str).reverse().toString(); int p2 = Integer.parseInt(reversestr, d); if( isPrime(n) && isPrime(p2)){
System.out.println("Yes");
}else{
System.out.println("No");
}
}
} public static boolean isPrime(int n) {
if (n == 1) {
return false;
}
for (int i = 2; i <= Math.sqrt(n); i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
}
PAT 甲级【1015 Reversible Primes】的更多相关文章
- 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 甲级 1015 Reversible Primes
https://pintia.cn/problem-sets/994805342720868352/problems/994805495863296000 A reversible prime in ...
- PAT甲级——A1015 Reversible Primes
A reversible prime in any number system is a prime whose "reverse" in that number system i ...
- PAT Advanced 1015 Reversible Primes (20) [素数]
题目 A reversible prime in any number system is a prime whose "reverse" in that number syste ...
- PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642
PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any n ...
- 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& ...
- PTA (Advanced Level) 1015 Reversible Primes
Reversible Primes A reversible prime in any number system is a prime whose "reverse" in th ...
随机推荐
- 错误:tensorflow.python.framework.errors_impl.InvalidArgumentError: ValueError: attempt to get argmax of an empty sequence的解决方案
近日,在使用Cascade R-CNN完成目标检测任务时,我在使用这个模型训练自己的数据集时出现了如下错误: 具体如以下截图所示: 详细错误如下所示: Traceback (most recent c ...
- 小知识:如何配置OSW添加私网监控
最近遇到一个Case,Oracle Support要求添加私网(心跳网络)监控. OSW默认是没有私网监控的,如需增加只需配置private.net文件,对应采集信息会存放到archive/oswpr ...
- python-命令行参数处理 getopt模块详解
背景 在写脚本程序的时候需要添加一些额外的参数来实现脚本的附加功能或者增强功能,通常的做法是通过sys.argv[i]直接来获取参数的值,但是这个比较局限,要求参数的输入一定要按照顺序. fileNa ...
- 【Flink入门修炼】1-3 Flink WordCount 入门实现
本篇文章将带大家运行 Flink 最简单的程序 WordCount.先实践后理论,对其基本输入输出.编程代码有初步了解,后续篇章再对 Flink 的各种概念和架构进行介绍. 下面将从创建项目开始,介绍 ...
- mysql5.7 大量sleep连接解决方法
show processlist 查看发现有大量sleep进程 查看当前数据库设置的最大连接数 show variables like 'max_connections'; 如果是生产环境需要紧急处理 ...
- push竟比concat快上数百倍?记一个concat在十万级数据引发的性能问题
壹 ❀ 引 公司产品一直在做企业项目研发工具,所以我们自己当然也会用自己的产品去管理公司大小项目,但在此之前,项目管理体验上一直存在一个卡顿问题.比如我刚登录上账号,在项目里随便到处点点到处跳转页面, ...
- JS leetcode 删除排序数组中的重复项 题解分析
壹 ❀ 引 一日一题,今天的题目来自于leetcode26. 删除排序数组中的重复项,其实在之前我们已经做了一道类似的题目,可参考JS leetcode 移除元素 题解分析,关于本题描述如下: 给定一 ...
- NC210981 mixup2混乱的奶牛
题目链接 题目 题目描述 混乱的奶牛 [Don Piele, 2007] Farmer John的 N(4 <= N <= 16) 头奶牛中的每一头都有一个唯一的编号 \(S_i (1 & ...
- 【Unity3D】固定管线着色器二
1 前言 固定管线着色器一 中介绍了 Shader 中外部属性.光照.贴图等基础用法,本文将进一步讲解固定管线着色器,介绍正面与反面剔除.Alpha 测试.深度测试.混合.渲染队列等用法.渲染管线 ...
- 【Unity3D】UGUI之Button
1 Button属性面板 在 Hierarchy 窗口右键,选择 UI 列表里的 Button 控件,即可创建 Button 控件,选中创建的 Button 控件,按键盘[T]键,可以调整 But ...