题目地址: 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. IT第三天 - 数据类型、转换、Scanner使用

    IT第三天 上午 变量类型 1.6种数值类型:byte.short.int.long.float.double:其中byte是8个字节,short是16字节,int是32字节.long是64字节:日常 ...

  2. BZOJ 1828

    program bzoj1828; ; check=; type node=record l,r,s,a:longint; end; ..maxn*] of node; a,b,c:..maxn] o ...

  3. hdu 1236 1.3.2排名

    排名 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission ...

  4. ArcGIS Engine 改变线IPolyline的方向

    有时候需要改变一下线的方向来组成要要的图形,可以按一下方法来变换一下. 如果看官有好的方法的话,请不吝贴上为谢! private IPolyline ChangeDirection(IPolyline ...

  5. AlertDialog具体解释

    对话框介绍与演示样例         对话框在程序中不是必备的,可是用好对话框能对我们编写的应用增色不少.採用对话框能够大大添加应用的友好性.比較经常使用的背景是:用户登陆.网络正在下载.下载成功或者 ...

  6. bootstrap框架开发电子商城案例

    bootstrap框架开发电子商城案例 玛图 bootstrap 商城框架

  7. python——登陆接口设计(循环方法)

    近日重新整理了登陆接口设计程序,感觉以前的代码没有注释,让园子的其他童鞋读起来比较费劲.也没有流程图和程序运行说明. 1.流程图 2.user_file.txt&lock_file.txt文件 ...

  8. qml+opencv(二),实现人脸检测

    http://blog.csdn.net/zhx6044/article/details/45048765

  9. 用nohup执行python程序时,print无法输出

    python -u参数:关闭输出缓冲 nohup python -u test.py > nohup.out 2>&1 &

  10. Android string.xml error: Apostrophe not preceded by \

    Android string.xml error: Apostrophe not preceded by \ 遇到了这个错误,编译无法通过 error: Apostrophe not preceded ...