设为首页 加入收藏

TOP

1015. Reversible Primes (20) PAT
2014-11-23 20:25:32 来源: 作者: 【 】 浏览:12
Tags:1015. Reversible Primes PAT

题目的意思是:给出一个数N和一个基数D。首先这个数必须是素数。其次,将这个数(1)转为D进制数(2)将这个D进制数反转(3)将反转后的数再转为十进制数,这个十进制数依然是素数。 这样我们就输出“Yes”。


判断素数:一个数N,如果从2到sqrt(N)都不存在因子,则认为这个数是素数。 注意:0和1不是素数。


将十进制数转为n进制数:(待补充。。。)

A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime.

Now given any two positive integers N (< 105) and D (1 < D <= 10), you are supposed to tell if N is a reversible prime with radix D.

Input Specification:

The input file consists of several test cases. Each case occupies a line which contains two integers N and D. The input is finished by a negative N.

Output Specification:

For each test case, print in one line "Yes" if N is a reversible prime with radix D, or "No" if not.

Sample Input:
73 10
23 2
23 10
-2
Sample Output:
Yes
Yes
No

#include
#include
#include
using namespace std;

bool is_Prime(int a)
{
	int i;
	if(a==0 || a==1) return false;

	//注意是i<=sqrt(),之前弄成i>N){
		if( N<0 ) break;
		cin>>D;
	    if( is_Prime(N) && is_Prime( change(N,D) )){
			cout<<"Yes"< 
 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 4638 Group(离线线段树) 下一篇C++四种强制类型转换详解

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python 数据分析与可 (2025-12-26 21:51:20)
·从零开始学Python之 (2025-12-26 21:51:17)
·超长干货:Python实 (2025-12-26 21:51:14)
·为什么 Java 社区至 (2025-12-26 21:19:10)
·Java多线程阻塞队列 (2025-12-26 21:19:07)