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 ...
随机推荐
- smartgit document merge
'Normal' Merge In case of a normal merge, a merge commit with at least two parent commits (i.e., the ...
- 关于List泛型的强制转换
当我们从数据库中查询出一些数据,有时返回的结果可能是List<Object>类型,而我们清楚的知道它的准确类型是List<User>,可能我们想直接的去进行类型的转换,你可能会 ...
- ADF_Starting系列1_JDeveloper IDE开发环境简介
2013-05-01 Created By BaoXinjian
- DBA_Oracle Startup / Shutdown启动和关闭过程详解(概念)
2014-08-07 Created By BaoXinjian
- 优化studio的速度
随着Android Studio开发工具的逐渐成熟,越来越多的程序员选择这种IDE工具来进行开发,但是android studio在使用过程中有时候会出现卡顿问题.在赶项目的时候,遇到这类问题最是苦恼 ...
- 安装Android SDK和ADT步骤和遇到的问题
http://894503895.diandian.com/post/2012-05-16/18695648 1.安装eclipse.下载地址:http://www.eclipse.org/downl ...
- 深入分析ConcurrentHashMap(转)
线程不安全的HashMap 因为多线程环境下,使用HashMap进行put操作会引起死循环,导致CPU利用率接近100%,所以在并发情况下不能使用HashMap,如以下代码 final HashMap ...
- MyBatis返回主键
网上给的例子都很简单 , 只要用useGeneratedKey就行了. @Insert({ "INSERT INTO money_record_increasement (id, creat ...
- git撤销命令
1 撤销工作区中master的修改 git checkout -- master.txt ,用暂存去覆盖工作区 2 git clean -n 查看哪些文件会被移除3 git clean -f 强制删除 ...
- 运行测试Caused by: java.lang.UnsatisfiedLinkError: no attach in java.library.path错误解决
解决办法:看到错误里面有个Caused by,说我的jdk运行到了32位的了,于是我查看环境变量,发现是昨天设置成32位的没有设置回来,于是设置回64位的jdk就ok了