POJ 2635.The Embarrassed Cryptographer
来源:互联网 发布:java预约系统源代码 编辑:程序博客网 时间:2024/05/19 23:12
题目:http://poj.org/problem?id=2635
AC代码(C++):
#include <iostream>#include <algorithm>#include <stdio.h>#include <vector>#include <queue>#include <math.h>#include <string>#include <string.h>#include <bitset>#define INF 0xfffffff#define MAXN 100105using namespace std;int primes[1000000];int k[50];int cnt;void table(){int pNum=0; primes[pNum++]=2; for(int i=3;i<=1000010;i+=2){ bool flag=true; for(int j=0;primes[j]*primes[j]<=i;j++) if(!(i%primes[j])) { flag=false; break; } if(flag) primes[pNum++]=i; } return;}int main(){char str[105];int l,len,maxcnt;table();while(cin>>str>>l){if(str[0]=='0'&&l==0)break;len = strlen(str);maxcnt = len/3;if(len%3==0)maxcnt--;for(cnt = maxcnt; cnt >= 0; cnt--){k[cnt] = 0;for(int j = 3; j >= 1; j--){if(len-(maxcnt-cnt)*3-j < 0)continue;k[cnt]*=10;k[cnt]+=str[len-(maxcnt-cnt)*3-j]-'0';}}int tmp;bool flag = true;for(int i = 0; primes[i] < l; i++){tmp = k[0]%primes[i];for(int j = 1; j <= maxcnt; j++){tmp = (tmp*1000+k[j])%primes[i];}if(tmp!=0)continue;cout<<"BAD "<<primes[i]<<endl;flag = false;break;}if(flag)cout<<"GOOD\n";}}总结: 题意很简单, 就是大数有点难处理. 看了dalao解题报告用了千进制来储存k, 然后用同余定理做.
阅读全文
0 0
- POJ 2635.The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- poj 2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- poj-2635-The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- poj 2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- 【POJ 2635】 The Embarrassed Cryptographer
- The Embarrassed Cryptographer(POJ--2635
- POJ-2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- dede:if DEDE模板中使用php和if判断语句的技巧
- Springboot实现quartz定时
- NKOJ 4345 (Ipsc2015)Generating Synergy (DFS序+kd树)
- 嵌入式软件工程师经典面试题
- yii2的url
- POJ 2635.The Embarrassed Cryptographer
- python学习_6
- Robot Framework 源代码阅读笔记 之二
- 东莞虎门一直都很不错滓
- Java中折半查找
- dede 模板 if dedecms模板中运用dede标签时使用php和if判断语句的方法
- 转义字符
- Python案例分析:中美汇率转换(2)
- 如何查看mysql数据库的物理存储路径