栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

1015 Reversible Primes (20 分)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

1015 Reversible Primes (20 分)

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

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
Sample solution:
#include  
using namespace std;

//计算题,重在理解题目中的定义,所谓n为基数d的反转素数<->十进制数n是素数,将n转化为d进制数后反转,反转数化为十进制后依然是素数
bool isprime(int n) {
    if(n <= 1) return false;
    int sqr = int(sqrt(n * 1.0));
    for(int i = 2; i <= sqr; i++) {
        if(n % i == 0)
            return false;
    }
    return true;
}
int main() {
    int n, d;
    int arr[100]={},num,sum=0;
    cin>>n;
    while(n>0){
    	cin>>d;
    	if(isprime(n)){
    		num=0;
    		while(n){
    			arr[num]=n%d;
    			n=n/d;
    			num++;
			}
			sum=0;
			for(int i=0;i>n;
	}
    return 0;
}
 Submit results attached

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/738859.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号