1015. Reversible Primes (20)
the problem is from PAT,which website is http://pat.zju.edu.cn/contests/pat-a-practise/1015
this problem is relatively easy.if there must be something which need to be noticed, i think
“1 is not a prime” could be one of them.
#include<stdio.h> bool isPrime(int n)
{
if (n == 1)
{
return false;
}
if (n == 2)
return true;
else
{
for (int i = 2; i < n; i++)
{
if (n % i == 0)
{
return false;
}
}
return true;
}
} int main()
{
int n,d;
while (scanf("%d",&n))
{
if (n < 0)
break;
scanf("%d",&d);
int temp = n;
int count = 0;
while (n/d != 0)
{
count += n%d;
count *= d;
n /= d;
}
count += n%d;
if (isPrime(temp)&&isPrime(count))
{
printf("Yes\n");
}
else
printf("No\n");
}
}
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分) 谜一般的题目,不就是个进制转换+素数判断
题目 A reversible prime in any number system is a prime whose "reverse" in that number syste ...
- 1015 Reversible Primes (20)(20 point(s))
problem A reversible prime in any number system is a prime whose "reverse" in that number ...
- 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 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 (Advanced Level) 1015. Reversible Primes (20)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT甲题题解-1015. Reversible Primes (20)-素数
先判断n是否为素数然后把n转化成d进制下再反转,转化为十进制的num判断num是否为素数 注意n为0和1时,不是素数!!!注意反转后的num也有可能为1,不是素数!!! #include <io ...
随机推荐
- 仿酷狗音乐播放器开发日志二十七 用ole为窗体增加文件拖动功能(附源码)
转载请说明原出处,谢谢~~ 中秋到了,出去玩了几天.今天把仿酷狗程序做了收尾,已经开发完成了,下一篇博客把完结的情况说一下.在这篇博客里说一下使用OLE为窗体增加文件拖拽的功能.使用播放器,我更喜欢直 ...
- ASP.NET 中JSON 的序列化和反序列化
JSON是专门为浏览器中的网页上运行的JavaScript代码而设计的一种数据格式.在网站应用中使用JSON的场景越来越多,本文介绍ASP.NET中JSON的序列化和反序列化,主要对JSON的简单介绍 ...
- QT4.7.4-vs2008和vs2010的安装并编写测试程序
QT的安装着实费了我好大的劲,之前试过QT5.1.0与VS2010的安装,但是因为设置的地方太多,程序运行总是不成功,所以最后选用QT4.7.4和VS2008与VS2010来编写程序.写这篇文章来总结 ...
- linux 常用命令基础
linux常用的命令 shell 是命令语句,命令解释程序以及程序设计语言的统称,它不仅仅拥有自己内建的shell命令集,同时也能被系统中其他应用程序所调用 shell 的一个重要特性是它本身就是一个 ...
- 你是怎么理解“MVC”的
MVC就是三个字母的组合,M-模型, V-视图, C-控制器. 这些在百度上随便一索就可以索到,而且网上对这三个部分的解释又过于笼统,使人没法完全理解MVC的含义. 这里我简单的谈谈我对MVC这三 ...
- hdu5909-Tree Cutting(树形dp)
偷偷抄bestcoser上面hnust_zhaozhixuan的代码 = = 因为题解看不懂阿 #include <cstdio> #include <cstring> typ ...
- homework-01 "最大子数组之和"的问题求解过程
写在前面:我的算法能力很弱,并且也是第一次写博文,总之希望自己能在这次的课程中学到很多贴近实践的东西吧. 1.这次的程序是python写的,这也算是我第一次正正经经地拿python来写东西,结果上来说 ...
- DBMS_ERRLOG记录DML错误日志(二)
上一篇简单介绍了DML记录语句的限制,虽然所有的例子都是利用INSERT语句,但是LOG ERRORS语句并没有这个限制,UPDATE.DELETE和MERGE都可以使用这个语句.下面要说的就是这篇的 ...
- JSF 2 textarea example
In JSF, you can use the <h:inputTextarea /> tag to render a HTML textarea field. For example, ...
- SCOI2016滚粗记
day0 又到了SCOI,照惯例赛前参加省选培训,住酒店但学校食堂很难吃. 省选培训被成七和南山的大爷虐翻,感觉进省队没什么戏,权当玩一玩吧. day1 早上醒的时候感觉脑袋很痛,想睡又睡不着,第二天 ...