【PAT甲级】1015 Reversible Primes (20 分)
题意:
每次输入两个正整数N,D直到N是负数停止输入(N<1e5,1<D<=10),如果N是一个素数并且将N转化为D进制后逆转再转化为十进制后依然是个素数的话输出Yes,否则输出No。
trick:
判断转化后的数是不是1,1不是素数,如果转化后不是1说明转化前也不会是1(第一个测试点错误原因)。
AAAAAccepted code:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,d;
while(cin>>n){
if(n<)
break;
cin>>d;
int flag=;
for(int i=;i*i<=n;++i)
if(n%i==)
flag=;
int a[]={};
int cnt=;
while(n){
a[++cnt]=n%d;
n/=d;
}
int x=;
for(int i=;i<=cnt;++i){
x*=d;
x+=a[i];
}
if(x==)
flag=;
for(int i=;i*i<=x;++i)
if(x%i==)
flag=;
if(flag)
cout<<"No"<<"\n";
else
cout<<"Yes"<<"\n";
}
return ;
}
【PAT甲级】1015 Reversible Primes (20 分)的更多相关文章
- 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 ...
- 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分) 谜一般的题目,不就是个进制转换+素数判断
题目 A reversible prime in any number system is a prime whose "reverse" in that number syste ...
- PAT (Advanced Level) Practice 1015 Reversible Primes (20 分)
A reversible prime in any number system is a prime whose "reverse" in that number system i ...
- PAT 甲级 1015 Reversible Primes
https://pintia.cn/problem-sets/994805342720868352/problems/994805495863296000 A reversible prime in ...
- PAT Advanced 1015 Reversible Primes (20) [素数]
题目 A reversible prime in any number system is a prime whose "reverse" in that number syste ...
- 1015 Reversible Primes (20 分)
A reversible prime in any number system is a prime whose "reverse" in that number system i ...
- PAT 甲级 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
随机推荐
- Python中的参数解包:`*`表达式和 `**`表达式
目录 1.参数解包:方法调用中的*表达式和**表达式 2.参数解包:方法定义中的*表达式和**表达式 3.在元组,列表,集合和字典中解包 4.Extended Unpacking:赋值表达式左边的*表 ...
- 如何用纯代码实现图片CSS3
在刷面试题的时候刷到2015阿里巴巴的,如何用代码实现下面的图形. <div class="main"> <h1>图片图标-一个标签实现</h1> ...
- .NET Core部署Windows服务
创建 首先你要确保你已经安装了.NET Core 3.0或以上版本. 老版本的Windows服务请看 这篇文章 使用命令行创建: dotnet new worker 使用Visual Studio创 ...
- 如何处理 Web 图片优化?
未优化的图片是影响网站性能的主要因素之一,尤其会影响初次加载.取决于图像的分辨率和画质,图片可能占据整个网站流量的 70%. 生产环境出现未优化的图片并显著影响初次加载速度的现象还是挺常见的.缺乏经验 ...
- Spring的简单介绍
struts2:web层hibernate:dao层spring:service层 1 spring框架概述 1.1 什么是springSpring是一个开源框架,Spring是于2003 年兴起的一 ...
- 2.1.FastDFS-单机拆分版-单机版安装配置
Centos610系列配置 1.什么是FastDFS? FastDFS是一个开源的分布式文件系统,她对文件进行管理,功能包括:文件存储.文件同步.文件访问(文件上传.文件下载)等,解决了大容量存储和负 ...
- Windows server 2012 R2 服务器用户自动锁定
开启共享文件夹后,发现经常会自动锁定导致,共享用户无法正常访问共享文件夹(原因不明) 解决办法,打开本地安全策略 把账户锁定阈值改为0
- werkeug的WSGI服务器解析
werkeug的WSGI服务器解析 1. WSGI 1.1. wsgi与flask flask默认的wsgi引用自wekurg 声明app:FLASK对象 app.run() run_ ...
- SpringBoot与Mybatis整合(包含generate自动生成代码工具,数据库表一对一,一对多,关联关系中间表的查询)
链接:https://blog.csdn.net/YonJarLuo/article/details/81187239 自动生成工具只是生成很单纯的表,复杂的一对多,多对多的情况则是在建表的时候就建立 ...
- TC301A芯片做的一种人体接近感应方案
基于TC301A芯片做的一种人体接近感应方案,此方案的原理是通过检测电容的变化量来检测人体的有无,此方案设计原理简单,使用方便,容易操作,成本较低.设计方案如下:可根据原理图做pcb板子,如图芯片的五 ...