浙大PAT甲级-1015
来源:互联网 发布:数据库怎么加锁 编辑:程序博客网 时间:2024/05/24 05:05
prime:素数;
1不是素数也不是合数。
#include <iostream>#include <vector>using namespace std;int num;bool isPrime(int a){ if(a==1) return false; for(int i=2;i<a;i++) if(a%i==0) return false; return true;}void change(int n, int d, vector<int> &x){ int cnt=0; while(n>0){ x.push_back(n%d); n/=d; cnt++; } num=cnt;}int Back(int d,vector<int> &x){ int n=0, m=1; for(int i=num-1;i>=0;i--){ n+=x[i]*m; m*=d; } return n;}int main(){ int n,d, cnt=0; vector<int> ans; while(cin>>n){ if(n<0) break; cin>>d; cnt++; vector<int> x; if(!isPrime(n)){ ans.push_back(0); continue; } change(n,d,x); if(!isPrime(Back(d,x))){ ans.push_back(0); continue; } ans.push_back(1); } for(int i=0;i<cnt;i++) if(ans[i]==1) cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0;}
阅读全文
0 0
- 浙大PAT甲级-1015
- 浙大pat甲级 1023
- 浙大pat甲级 1024
- 浙大pat甲级 1025
- 浙大PAT甲级 1026
- 浙大PAT甲级 1028
- 浙大PAT甲级 1029
- 浙大PAT甲级 1030
- 浙大PAT甲级 1031
- 浙大PAT甲级 1032
- 浙大PAT甲级 1033
- 浙大PAT甲级 1035
- 浙大PAT甲级 1037
- 浙大PAT甲级 1039
- 浙大PAT甲级 1040
- 浙大PAT甲级 1038
- 浙大PAT甲级 1041
- 浙大PAT甲级 1042
- python002简单的输入输出
- 前端开发:关于引用外部文件的顺序问题
- Android studio 打开新文件 同一个窗口
- yolo v2文件结构和源码的简单梳理
- 机房模拟赛 2017.7.3
- 浙大PAT甲级-1015
- STL常用函数复习之————deque
- 拉丁方阵
- HTML5小游戏
- 统计SQuAD的词汇得到word2id 并把词都转成id的python代码
- 2017年7月,桌面分享
- java随机生成6位随机数 5位随机数 4位随机数
- Django-中间件Middleware
- QStackedWidget实现左侧列表与右侧控件关联