2012年3月15日

Poj 1006

摘要: 中国剩余定理简单应用#include <iostream>#include <stdio.h>using namespace std;int b[3],w[3];//a=b[i](%w[i]);int exgcd(int a,int b,int &x,int &y){ if(0==b){x=1;y=0;return a;} int d=exgcd(b,a%b,x,y); in... 阅读全文

posted @ 2012-03-15 20:41 Inpeace7 阅读(121) 评论(0) 推荐(0) 编辑

算法导论-----数论-----中国余数定理

摘要: 1. 定理。n=n1n2…nk,且ni间两两互质,a<---->(a1,a2,…,ak),a属于,ai属于,且i=1,2…kai=amodni。若 a<----->(a1,a2,…,ak) b<----->(b1,b2,…bk)那么a+b<----->((a1+b1)modn1,(a2+b2)modn2,…,(ak+bk)modnk)a-b<----->((a1-b1)modn1,(a2-b2)modn2,…,(ak-bk)modnk)ab<----->((a1b1)modn1,(a2b2)modn2,…,(akbk)mo 阅读全文

posted @ 2012-03-15 19:16 Inpeace7 阅读(767) 评论(0) 推荐(0) 编辑

Poj 2115

摘要: 模线性方程,水题#include <iostream>#include <stdio.h>using namespace std;typedef long long ll;ll exgcd(ll a,ll b,ll &x,ll &y){ if(b==0){x=1;y=0;return a;} ll d=exgcd(b,a%b,x,y); ll t=x; x=y; ... 阅读全文

posted @ 2012-03-15 19:12 Inpeace7 阅读(156) 评论(0) 推荐(0) 编辑

Poj 1061

摘要: 经典的线性模方程,考点在求最小正根#include <iostream>#include <stdio.h>using namespace std;typedef long long ll;ll exgcd(ll a,ll b,ll &x,ll &y){ if(b==0){x=1;y=0;return a;} ll d=exgcd(b,a%b,x,y); ll t=x; ... 阅读全文

posted @ 2012-03-15 16:36 Inpeace7 阅读(137) 评论(0) 推荐(0) 编辑

算法导论-----数论-----求解模线性方程

摘要: ax=b(modn) 设<a>是模n加法群中的循环子群,即<a>={}={axmodn},所以有一个解当且仅当b属于<a>,而|<a>|必定是n的约数 对任意正整数a,n,若d=gcd(a,n),在中 <a>=<d>={0,d,2d,3d…(n/d-1)d}所以|<a>|=n/d; 证明:(1)<d>属于<a> ax+ny=d,ax=d(modn),d的倍数属于a (2)<a>属于<d> 设m属于<a> ax=m(modn),ax+ny=m,d|ax+ 阅读全文

posted @ 2012-03-15 11:18 Inpeace7 阅读(272) 评论(0) 推荐(0) 编辑

Poj 3641

摘要: 水题,纯套millerrabin模板#include <stdio.h>#include <iostream>#include <stdlib.h>#include <time.h>#include <cmath>#include <algorithm>#include <string.h>using namespace std;typedef long long ll;ll mulmod(ll ... 阅读全文

posted @ 2012-03-15 11:09 Inpeace7 阅读(202) 评论(0) 推荐(0) 编辑

Poj 3696 miller-rabin pollard-rho解法

摘要: 挺好的题目(1)888…8可以表示为8*10^0+8*10^1+…+8*10^(n-1)可看出,抽出每一项组成等比数列,根据等比数列和公式,得,8/9(10^n-1)所以8/9(10^n-1)=kL,k为正整数,即L|(8/9(10^n-1))(2)令gcd(8,L)=s,故(10^n-1)*8/s=9kL/s8,9互素,故8/s与9L/s互素,故10^n-1=0(mod 9L/s)10^... 阅读全文

posted @ 2012-03-15 10:52 Inpeace7 阅读(549) 评论(0) 推荐(0) 编辑

导航