//题的理解是n在基数b中的的表示中,正序和逆序值都是素数,但是其实可直接判断n,因为n在b中的正常序列值就是再换成十进制就是n,但是不A;不知道为什么

用笨方法,先把n展开成b进制,正常计算其实是翻转值,倒序是正常序列值,两者都是素数时,yes,否则no,A了

也可以用atoi或者itoa但是本地可以,linix系统不支持这两个c函数,可以用c++里的string试试,直接把字符串变成数值貌似可以,小白还没解锁该技巧;

#include<cstdio>
#include<cmath>
int isprim(int s)
{
int i,t=(int)sqrt(s);
if(s<=1)return 0;
for(i=2;i<=t;i++)
if(s%i==0)return 0;
return 1;
}
int main()
{
freopen("input.txt","r",stdin);
int i,n,b;
while(scanf("%d",&n)!=EOF&&n>=0)
{
//if(!isprim(n))printf("No\n");
//else
{
scanf("%d",&b);
int len=0,s[33];
do
{
s[len++]=n%b;
n=n/b;
}while(n!=0);
int s1=0,s2=0;
for(i=len-1;i>=0;i--)s1=s1*b+s[i];
for(i=0;i<len;i++)s2=s2*b+s[i];
//printf("%d\n",n);
if(isprim(s1)&&isprim(s2)) printf("Yes\n");
else printf("No\n");
}
}
return 0;
}

PAT1015. Reversible Primes的更多相关文章

  1. pat1015. Reversible Primes (20)

    1015. Reversible Primes (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A r ...

  2. PAT-1015 Reversible Primes (20 分) 进制转换+质数

    A reversible prime in any number system is a prime whose "reverse" in that number system i ...

  3. PAT 1015 Reversible Primes

    1015 Reversible Primes (20 分)   A reversible prime in any number system is a prime whose "rever ...

  4. PAT 甲级 1015 Reversible Primes(20)

    1015 Reversible Primes(20 分) A reversible prime in any number system is a prime whose "reverse& ...

  5. PAT 1015 Reversible Primes[求d进制下的逆][简单]

    1015 Reversible Primes (20)(20 分)提问 A reversible prime in any number system is a prime whose "r ...

  6. PTA (Advanced Level) 1015 Reversible Primes

    Reversible Primes A reversible prime in any number system is a prime whose "reverse" in th ...

  7. PAT_A1015#Reversible Primes

    Source: PAT A1015 Reversible Primes (20 分) Description: A reversible prime in any number system is a ...

  8. pat 1015 Reversible Primes(20 分)

    1015 Reversible Primes(20 分) A reversible prime in any number system is a prime whose "reverse& ...

  9. PAT 甲级 1015 Reversible Primes (20 分) (进制转换和素数判断(错因为忘了=))

    1015 Reversible Primes (20 分)   A reversible prime in any number system is a prime whose "rever ...

随机推荐

  1. PL/SQL查询Oracle数据乱码/Oracle客户端乱码解决办法

    [如果此方法都试了就是不行,那么就重复尝试,先把环境变量给删了,注册表里的键值也删除了,然后重启,再配置,肯定行!我试过!] 先确定Oracle服务器采用的是何种编码: select userenv( ...

  2. DBA_Tablespace表空间的概念和管控(概念)

    2014-07-24 Created By BaoXinjian

  3. OAF_VO系列1 - Accelerator Keys

    OAF_EO系列6 - Delete详解和实现(案例) (2014-06-16 08:37)

  4. HDU 2717 Catch That Cow(BFS)

    Catch That Cow Farmer John has been informed of the location of a fugitive cow and wants to catch he ...

  5. Android网络通信库Volley简介

    1. 什么是Volley 在这之前,我们在程序中需要和网络通信的时候,大体使用的东西莫过于AsyncTaskLoader,HttpURLConnection,AsyncTask,HTTPClient( ...

  6. cvc-elt.1: 找不到元素 'beans' 的声明

    这次遇到的这个错误又坑爹又低级 , 是因为网上抄到了错误的xsd搞的. 这是网上抄到的 xsi:schemalocation=" http://www.springframework.org ...

  7. ajax实现的无刷新分页代码实例

    一.html代码部分: <table class="table style-5">   <thead id="t_head">     ...

  8. Android学习笔记02

    1.线性布局LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&q ...

  9. 数组排序-冒泡排序-选择排序-插入排序-希尔排序-快速排序-Java实现

    这五种排序算法难度依次增加. 冒泡排序: 第一次将数组相邻两个元素依次比较,然后将大的元素往后移,像冒泡一样,最终最大的元素被移到数组的最末尾. 第二次将数组的前n-1个元素取出,然后相邻两个元素依次 ...

  10. 在MS CRM 4.0中引用JS文件

    引用: http://blog.csdn.net/qzw4549689/article/details/6027987 1.编写好JS代码,在ISV目录下新建一个目录javascripts,将JS文件 ...