博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT_A 1015. Reversible Primes (20)
阅读量:4226 次
发布时间:2019-05-26

本文共 1528 字,大约阅读时间需要 5 分钟。

1015. Reversible Primes (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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 1023 223 10-2
Sample Output:
YesYesNo
做麻烦了,从输入的a中取出最后一位可以直接拿过来当反转的第一位来用,以此类推,没有必要再生成字符串。
import java.util.*;public class Main {	public static boolean IsPrime(int a) {		if(a==1)			return false;		else if(a==2)			return true;		else {			for(int i=2;i*i<=a;i++) {				if(a%i==0)					return false;			}			return true;		}	}	public static void main(String[] args) {		// TODO Auto-generated method stub		Scanner in=new Scanner(System.in);		int a=in.nextInt();		while(a>0) {			int radix=in.nextInt();			String as=new String("");			String ass=new String("");			int num=0;			int aa=a;			while(a>0) {				char ch;				int dig=a%radix;				ch=(char)('0'+dig);				as=ch+as;				a/=radix;			}			int len=as.length();			for(int i=len-1;i>-1;i--) {				char ch=as.charAt(i);				ass=ass+ch;			}			for(int i=0;i

转载地址:http://gtdqi.baihongyu.com/

你可能感兴趣的文章
中科院计算所Goddon CPU诞生历史!牛!
查看>>
ispPAC
查看>>
迷你型的 Linux 系统
查看>>
为人处世小技巧
查看>>
C++ 堆、栈及静态数据区详解
查看>>
VC++6.0编译环境介绍
查看>>
74芯片特性分类使总汇
查看>>
ttl和cmos的区别
查看>>
常见逻辑电平标准
查看>>
逻辑电平的含义
查看>>
103个Windows XP运行命令
查看>>
常用linux命令大全
查看>>
上下拉电阻的用法
查看>>
TTL和CMOS的区别
查看>>
什么是上拉电阻和下拉电阻,上拉电阻和下拉电阻有什么应用?
查看>>
基于嵌入式微处理器EP9315的二次开发技术
查看>>
物理地址和虚拟地址
查看>>
s3c2410 MMU
查看>>
C语言宏
查看>>
ACM学习网站
查看>>