1015 Reversible Primes

PAT 1015 Reversible Primes python解法 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 becau... 阅读详情

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 (<10​5​​) 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

AC代码:(素数+进制转换(转化为十进制))

 #include <iostream>
#include <bits/stdc++.h>
using namespace std;
int p[(int)1e7+10];
void prime()
{
    p[0] = 1;
    p[1] = 1;
    for(int i=2; i<=(int)1e7+10; i++)
    {
        if(p[i]==0)
        {
            for(int j=i+i; j<=(int)1e7+10; j=j+i)
            {
                p[j] = 1;
            }
        }
    }
}
int main()
{
    prime();
    int n,d;
    queue<int>q;
    while(~scanf("%d%d",&n,&d))
    {
        if(n<0)
            break;
        if(p[n]==0)
        {
            int m = n;
            while(m)
            {
                q.push(m%d);
                m = m / d;
            }
            int s = 0;
            while(!q.empty())
            {
                s=s*d+q.front();
                q.pop();
            }
           // printf("%d\n",s);
            if(p[s]==0)
            {
                printf("Yes\n");
            }
            else
            {
                printf("No\n");
            }
        }
        else
        {
            printf("No\n");
        }
    }
    return 0;
}

Windows NPS与华为、华三、思科设备RADIUS认证实战指南 本文详细介绍了Windows NPS与华为、华三、思科设备RADIUS认证的实战配置指南。通过NPS服务器统一管理网络设备认证,实现企业级安全访问控制,涵盖基础配置、设备对接及故障排查方法,助力管理员提升网络安全管理效率。 阅读详情

相关推荐

类银河恶魔城游戏开发学习笔记(0)

解决B站搬运【Unity教程】从0编程制作类银河恶魔城游戏P37中moveState和idleState循环切换的问题

Gellar的博客 1448

【PAT(甲级)】1015 Reversible Primes

【PAT(甲级)】1015 Reversible Primes 思路分享,易错点分析

weixin_55202895的博客 325

构建高可用CephFS NFS网关:NFS-Ganesha与RADOS集群的深度整合

本文详细介绍了如何构建高可用的CephFS NFS网关,通过NFS-Ganesha与RADOS集群的深度整合,实现高效文件共享。文章涵盖核心架构、部署实战、性能调优及避坑指南,帮助用户解决Ceph客户端兼容性问题,提升存储访问效率。特别强调高可用设计,确保服务稳定性,适用于金融、电商等高要求场景。

weixin_26976635的博客 254

甲级PAT 1015 Reversible Primes(大量素数经典方法+二分查找)

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 pr...

Joyceyang_999的博客 340

liquibase介绍

1、Liquibase还是Flyway Flyway和Liquibase都支持专业数据库重构和版本控制所需的所有功能,因此您将始终知道要处理的数据库模式的版本以及它是否与软件版本匹配。两种工具都集成在Maven或Gradle构建脚本中以及Spring Boot生态系统中,因此您可以完全自动化数据库重构。 Flyway使用SQL定义数据库更改,因此您可以定制SQL脚本,使其与基础数据库技术(例如Oracle或PostgreSQL)良好地配合使用。另一方面,使用Liquibase,您可以通过使用XML,YA

赶路人儿 7534

解锁激光加工密码:功率、频率、脉宽、占空比全解析

激光加工利用高能量激光束实现材料加工,具有无接触、高效率等特点。其核心参数包括功率(决定能量输出)、频率(控制脉冲重复)、脉宽(调节能量作用时间)和占空比(调控工作周期),这些参数相互协同影响加工效果。针对不同材料需采用差异化参数组合:金属材料需较高功率,塑料需低功率防过热,陶瓷需高频短脉宽减少热应力。实际操作中应通过小范围测试逐步优化参数,并注意解决烧损、切割不平整等常见问题。合理调节这些参数可实现高质量、高效率的激光加工。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 617

1015 Reversible Primes(超详细注解,41行代码)

1015 Reversible Primes(超详细注解,41行代码)

m0_66329385的博客 161

保边滤波之Mean shift filter

保边滤波之Mean shift filter 目录 保边滤波之Mean shift filter 一、算法原理 二、练手实现的算法代码如下: 三、实现结果 一、算法原理 在OpenCV中,meanshift filter函数为 p...

大熊 1561

1015 Reversible Primes (20 分) PAT 甲级 一定要读懂题意

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 beca...

小渣渣的博客 276

uniapp - 解决报错Error in event handler for “service.requestComponentInfo“: “TypeError: cannot read prop

uniapp,报错,Error in event handler for "service.requestComponentInfo": "TypeError: cannot read properties of undefined (reading 'matches')",h5移动端网页,微信小程序,支付宝小程序,Android安卓,苹果ios,app,nvue,如何解决这个问题,一直报错,uniapp报错Error,都检查了还是报错,怎么解决这个错误,uniapp出现Error in event han

🏆 前端领域优质创作者 6379

华为MetaERP PTP采购到应付全流程解析

摘要:本文系统解析华为MetaERP中的PTP(采购到应付)全流程管理方案,涵盖从采购申请到付款执行的完整业务流程。文章详细分解了PR、PO、GR、IV、AP等关键环节的财务核算规则,并提供了预算校验、库存更新等Python代码示例。同时阐述了IT落地架构设计,包括会计引擎配置、系统集成方案及银企直连支付接口实现。该方案通过三单匹配自动化和智能会计引擎,将处理效率提升10倍(200笔/人天→2000笔/人天),实现98%的自动化率,为集团企业提供了高效的数字化财务管理样板。文中所有技术方案均需根据实际场景调

金牌架构师 1743

1015 Reversible Primes(质数)

1015 Reversible Primes

老顽固也可爱 427

区块链技术与应用 【全国职业院校技能大赛国赛题目解析】Caliper从0到使用

技能大赛样题解析,caliper题目从0到使用

weixin_52865146的博客 2078

1015 Reversible Primes (20 分)

1015 Reversible Primes (20 分) 题目大意: 给出一个正整数N和D 如果N是素数 且 N的D进制 逆序 再转回十进制 也是素数 那么就输出Yes 否则No 分析: 筛法求素数 然后要注意1不是素数 AC代码: #include <iostream> #include <cstring> #include <cmath> using na...

Fighting_Eagle的博客 502

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

PAT-1015 Reversible Primes(1不是素数)

1015Reversible Primes(20分) Areversible primein 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 beca...

得未曾有 心净踊跃 292

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

PAT 1015 Reversible Primes

PAT 1015 Reversible Primes 进制转换+素数判断+模拟

2301_80219163的博客 260

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

1015 Reversible Primes 简单解法

题目 题目链接:1015 Reversible Primes (PAT (Advanced Level) Practice) 输入样例 73 10 23 2 23 10 -2 输出样例 Yes Yes No 提交结果截图 带详细注释的源代码 #include <iostream> #include <cstdio> using namespace std; typedef long long ll; //判断是否是质数,是则返回1,否则返回0 int.

NOT_TODAY1的博客 350

PAT 甲级 1015  Reversible Primes

1015 Reversible Primes (20 point(s)) 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 pri...

漫浸天空的雨色的备忘录~ 1032

PAT 甲级 1015 Reversible Primes

PAT 甲级 1015 Reversible Primes #include <bits/stdc++.h> using namespace std; const int kPRIME_SIZE = 100010; bool is_prime[kPRIME_SIZE]; int re_D(int n, int D) { vector<int> n_D; int ans = 0; // 转换进制后翻转 while (n != 0) { n

桂圆儿的仓库 99

Python每日一题——PTA甲级1015 Reversible Primes

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 (<10 5 ) and D

Sechoice的博客 699

PAT甲级 1015 Reversible Primes

PAT甲级 1015 Reversible Primes 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 becaus...

旺崽的博客 2822
上一篇: 学生信息的添加与查询
下一篇: 1031 Hello World for U (20 分)(其实这个题目有更简单的方法)
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值