PAT1015. Reversible Primes
//题的理解是n在基数b中的的表示中,正序和逆序值都是素数,但是其实可直接判断n,因为n在b中的正常序列值就是再换成十进制就是n,但是不A;不知道为什么
用笨方法,先把n展开成b进制,正常计算其实是翻转值,倒序是正常序列值,两者都是素数时,yes,否则no,A了
也可以用atoi或者itoa但是本地可以,linix系统不支持这两个c函数,可以用c++里的string试试,直接把字符串变成数值貌似可以,小白还没解锁该技巧;
#include<cstdio>
#include<cmath>
int isprim(int s)
{
int i,t=(int)sqrt(s);
if(s<=1)return 0;
for(i=2;i<=t;i++)
if(s%i==0)return 0;
return 1;
}
int main()
{
freopen("input.txt","r",stdin);
int i,n,b;
while(scanf("%d",&n)!=EOF&&n>=0)
{
//if(!isprim(n))printf("No\n");
//else
{
scanf("%d",&b);
int len=0,s[33];
do
{
s[len++]=n%b;
n=n/b;
}while(n!=0);
int s1=0,s2=0;
for(i=len-1;i>=0;i--)s1=s1*b+s[i];
for(i=0;i<len;i++)s2=s2*b+s[i];
//printf("%d\n",n);
if(isprim(s1)&&isprim(s2)) printf("Yes\n");
else printf("No\n");
}
}
return 0;
}
PAT1015. Reversible Primes的更多相关文章
- pat1015. Reversible Primes (20)
1015. Reversible Primes (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A r ...
- PAT-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
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 ...
- PTA (Advanced Level) 1015 Reversible Primes
Reversible Primes A reversible prime in any number system is a prime whose "reverse" in th ...
- PAT_A1015#Reversible Primes
Source: PAT A1015 Reversible Primes (20 分) Description: A reversible prime in any number system is a ...
- 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 ...
随机推荐
- Codeforces Round #359 (Div. 2)C - Robbers' watch
C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)
B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Spring中的AOP应用
AOP被称为面向切面编程,AOP中的几个重要概念是: 1.切面.切面就是要实现的功能.切面通常是在多数方法中会用到的相同功能,如写日志. 2.连接点.连接点就是应用程序执行过程中插入切面的地点.如:方 ...
- U盘安装Linux CentOS 6.5 64位操作系统(来自互联网)
从centOS6.5开始直接把iso文件写入u盘就行了. 方法1:windows平台:1.用UltraISO打开iso(如:CentOS-6.5-x86_64-bin-DVD1.iso)2.然后点“启 ...
- 在Windows 7上安装MongoDB 2.6.7
sc.exe create MongoDB binPath= "C:\mongodb\bin\mongod.exe --service --config=\"C:\mongodb\ ...
- struts2 使用注解方式配置
1.导入convention 包 2.java: package com.struts.base.hello; import java.io.IOException; import java.io.P ...
- position中多次用到了relative和absolute,能不能具体介绍一下这两者的区别?
position中多次用到了relative和absolute,能不能具体介绍一下这两者的区别? 一个是相对定位,一个是绝对定位. absolute生成绝对定位的元素,相对于 static 定位以外的 ...
- VisualVM连接远程Java进程
jstatd是一个RMI(Remove Method Invocation)的server应用,用于监控jvm的创建和结束,并且提供接口让监控工具(如VisualVM)可以远程连接到本机的jvms . ...
- [转载]python中将普通对象作为 字典类(dict) 使用
目前我知道的有两种方法: 1 定义的类继承dict类 例如 class A(dict): pass a = A() a['name'] = 12 2 给自定义的类添加 __setitem__() __ ...
- Altium designer 原理图库快速创建
Altium designer 原理图库快速创建,原来都没发现用这个功能,最近查了一下很好用,就是通过Excel编写管脚名称再直接导入就可以了,很方便的. 1.首先在Excel创建填好对应管脚名称. ...