当前位置:网站首页>PAT 1015 进制转换
PAT 1015 进制转换
2022-08-09 11:09:00 【AlanLiu6】
无语
#include<cstdio>
#include<cstring>
// 十进制转任意进制(暂时只转十进制以内
char str[15];
int prime(int n)
{
if(n < 2) return 1; // 坑点
for(int i = 2; i <= n/2;i++)
{
if(n%i == 0)
{
// printf("%d %d\n",i,n/i);
return 1;
}
}
return 0;
}
int transRadix(int n,int r)
{
memset(str,'\0',sizeof(str));
int w = 0;
int t = n;
while(t)
{
int b = t % r;
char a = b + '0';
t = t /r;
str[w++] = a;
}
int sum = 0;
for(int i = w-1,j = 1;i>=0;i--,j*=r)
{
sum += (str[i] - '0')*j;
}
return sum;
}
int main()
{
int N,D;
while(scanf("%d",&N)!= EOF && N > 0)
{
scanf("%d",&D);
int sum = transRadix(N,D);
int ans1 = prime(sum);
int ans2 = prime(N);
if(!ans1 && !ans2) printf("Yes\n");
else printf("No\n");
}
return 0;
}
边栏推荐
猜你喜欢
随机推荐
Product Quantization (PQ)
ThreadLocal及其内存泄露分析
log4net使用指南(winform版,sqlserver记录)
论文分享 | ACL2022 | 基于迁移学习的论元关系提取
Paper Sharing | ACL2022 | Argument Relation Extraction Based on Transfer Learning
性能测试(04)-表达式和业务关联-JDBC关联
去除蜂窝状的噪声(matlab实现)
enum in c language
学习阶段总结(背包问题)
Preparation for gold three silver four: how to successfully get an Ali offer (experience + interview questions + how to prepare)
ECCV 2022 Oral | CCPL: 一种通用的关联性保留损失函数实现通用风格迁移
Missing URI template variable ‘employeeNumber‘ for method parameter of type String
Tensorflow realize parameter adjustment of linear equations
1009 Product of Polynomials C语言多项式乘积(25分)
vite的原理,手写vite
sublime记录
ACM最长不下降子序列问题
PTA习题 阶梯电价(C)
leetcode-搜索旋转排序数组-33
mysql参数学习----max_allowed_packet