题目地址: http://poj.org/problem?id=2635

题意:给出一个n和L,一直n一定可以分解成两个素数相乘。

让你判断,如果这两个素数都大于等于L,则输出GOOD,否则输出最小的那个素数。

从1到1000000的素数求出来,然后一个一个枚举到L,看能否被n整除,能的话就输出BAD+改素数

都不行的话,说明两个素数都大于等于L,输出GOOD

AC代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std; typedef long long LL;
const int N=1000005;
const LL II=100000000;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0); LL pri[N/100];
bool num[N];
int xx;
char s[105];
LL x[100]; void prime()
{
LL i,j;
int k=0;
memset(num,0,sizeof(num));
for(i=2;i<N;i++)
{
if(!num[i])
{
pri[++k]=i;
for(j=i;j<N;j+=i)
num[j]=1;
}
}
xx=k;
} void toint(char *s,LL *t,int &k)
{
int len=strlen(s),j;
char x[10]={0};
k=0;
for(;len/8;len-=8)
{
strncpy(x,s+len-8,8);
LL sum=0;
for(j=0;j<8;j++)
sum=sum*10+x[j]-'0';
t[k++]=sum;
}
if(len)
{
strncpy(x,s,len);
LL sum=0;
for(j=0;j<len;j++)
sum=sum*10+x[j]-'0';
t[k++]=sum;
}
} bool modd(LL p,int len)
{
int i;
LL xh=0;
for(i=len-1;i>=0;i--)
xh=(xh*II+x[i])%p;
if(xh==0)
return true;
return false;
} int main()
{
int i,j,L;
prime();
while(scanf("%s%d",s,&L))
{
if(strcmp(s,"0")==0&&L==0)
break;
int len;
toint(s,x,len);
int p=1,flag=0;
while(pri[p]<L)
{
if(modd(pri[p],len))
{
flag=1;
printf("BAD %lld\n",pri[p]);
break;
}
p++;
}
if(flag==0)
printf("GOOD\n");
}
return 0;
}

POJ 2635 The Embarrassed Cryptographer 高精度的更多相关文章

  1. POJ 2635 The Embarrassed Cryptographer

    大数取MOD... The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1 ...

  2. [ACM] POJ 2635 The Embarrassed Cryptographer (同余定理,素数打表)

    The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11978   A ...

  3. POJ 2635 The Embarrassed Cryptographer (千进制,素数筛,同余定理)

    The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15767   A ...

  4. poj 2635 The Embarrassed Cryptographer(数论)

    题目:http://poj.org/problem?id=2635 高精度求模  同余模定理. 题意: 给定一个大数K,K是两个大素数的乘积的值.再给定一个int内的数L 问这两个大素数中最小的一个是 ...

  5. POJ 2635 The Embarrassed Cryptographer 大数模

    题目: http://poj.org/problem?id=2635 利用同余模定理大数拆分取模,但是耗时,需要转化为高进制,这样位数少,循环少,这里转化为1000进制的,如果转化为10000进制,需 ...

  6. POJ - 2635 The Embarrassed Cryptographer(千进制+同余模)

    http://poj.org/problem?id=2635 题意 给一个大数K,K一定为两个素数的乘积.现给出一个L,若K的两个因子有小于L的,就输出BAD,并输出较小的因子.否则输出GOOD 分析 ...

  7. POJ 2635 The Embarrassed Cryptographer(大数求余)

    题意:给出一个大数,这个大数由两个素数相乘得到,让我们判断是否其中一个素数比L要小,如果两个都小,输出较小的那个. 分析:大数求余的方法:针对题目中的样例,143 11,我们可以这样算,1 % 11 ...

  8. POJ2635——The Embarrassed Cryptographer(高精度取模+筛选取素数)

    The Embarrassed Cryptographer DescriptionThe young and very promising cryptographer Odd Even has imp ...

  9. 【阔别许久的博】【我要开始攻数学和几何啦】【高精度取模+同余模定理,*】POJ 2365 The Embarrassed Cryptographer

    题意:给出一大数K(4 <= K <= 10^100)与一整数L(2 <= L <= 106),K为两个素数的乘积(The cryptographic keys are cre ...

随机推荐

  1. ios7下二维码功能的实现

    苹果公司升级到IOS7后自己的PassBook自带二维码扫描功能,所以现在使用二维码功能不需要在借助第三方库了 使用前请先导入AVFoundation.frameWork // //  YHQView ...

  2. CoreAnimation (CALayer 动画)

    CoreAnimation基本介绍: CoreAnimation动画位于iOS框架的Media层 CoreAnimation动画实现需要添加QuartzCore.Framework CoreAnima ...

  3. HDU 5281 Senior&#39;s Gun

    Senior's Gun Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

  4. JavaScript语言基础知识6

    在前面的章节中,我们知道JavaScript代码,字符和数字值当添加,将计值转换成字符,即用户输入的数目值它们被转换为字符. 如今我们要做这种样例,我想将1和2相加: <HTML> < ...

  5. [每天一个Linux小技巧] gdb 下一次运行多个命令

    一般gdb运行的时候,我们仅仅能输入一个命令. 如: (gdb) c (gdb) bt 假设想运行多个命令怎么办? 能否像bash那样, 使用; 如 ls; ls 结论是不行. 但能够通过gdb 内建 ...

  6. MYSQL - php 使用 localhost 无法连接数据库

    php 使用 localhost 无法连接数据库,而使用127.0.0.1却能连接成功. 可能原因: 系统hosts文件未提供127.0.0.1到localhost的解析.解决方法(以win7系统为例 ...

  7. Objective-C开发编码规范:4大方面解决开发中的规范性问题

    Objective-C 编码规范,内容来自苹果.谷歌的文档翻译,自己的编码经验和对其它资料的总结. 概要 Objective-C 是一门面向对象的动态编程语言,主要用于编写 iOS 和 Mac 应用程 ...

  8. (Problem 17)Number letter counts

    If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + ...

  9. eclipse 找不到application选项

    处理如下:Window-Preferences-Run/Debug-Perspectives 中的 And Build修改为如下

  10. javacoo/CowSwing 丑牛迷你采集器

    丑牛迷你采集器是一款基于Java Swing开发的专业的网络数据采集/信息挖掘处理软件,通过灵活的配置,可以很轻松迅速地从 网页上抓取结构化的文本.图片.文件等资源信息,可编辑筛选处理后选择发布到网站 ...