码迷,mamicode.com
首页 >  
搜索关键字:exgcd    ( 307个结果
逆元小结
一、若a与n互素,那么可以用扩展欧几里德和欧拉函数求出a对于n的逆元。 ax≡1(mod n),x为a对于n的逆元。 用欧几里德求逆元x: //a与n互素,逆元才有解 #include #include using namespace std; typedef long long LL; void exgcd(LL a,LL b,LL &d,LL &x,LL &y) { if(!b)...
分类:其他好文   时间:2015-08-15 18:26:34    阅读次数:97
扩展欧几里德 poj1061 青蛙的约会
扩展欧几里德非常经典,但是也有时候挺难用的。一些东西一下子想不明白。。 于是来了一个逆天模板。。只要能列出Ax+By=C,就能解出x>=bound的一组解了~ LL exgcd(LL a, LL b, LL &x, LL &y) { if(b == 0) { x = 1; y = 0; return a; } LL r = exgcd(b...
分类:其他好文   时间:2015-08-15 10:25:48    阅读次数:115
中国剩余定理模板poj1006
#include #include #include #include #include #include using namespace std;typedef long long ll;const int maxn = 20;ll exgcd(ll a, ll b, ll &x, ll &y){...
分类:其他好文   时间:2015-08-07 14:39:15    阅读次数:81
扩展欧几里得算法
对于 a 、b 不全为0,存在整数 x 和 y 使得 gcd(a,b)=x*a+y*b ; 整数。。。也就是可以使负的。 代码: 1 int exGcd(int a,int b,int &x,int &y) 2 { 3 if(b==0) 4 { 5 x=1; 6 y=0...
分类:编程语言   时间:2015-08-06 01:56:41    阅读次数:126
乘法逆元+排列组合模板
妈妈呀我终于会写乘法逆元+排列组合了。 1 void exgcd(int a,int b,int&x,int&y){ 2 if(b==0){x=1;y=0;return;}exgcd(b,a%b,x,y);int t=x;x=y;y=t-a/b*y; 3 } 4 int qpow(int x...
分类:其他好文   时间:2015-07-10 13:08:42    阅读次数:142
拓展gcd解不定线性方程ax+by=c模版
拓展gcd解不定线性方程ax+by=c模版/** 解不定方程 ax+by=c */ll a,b,c;ll x,y;ll exgcd(ll a,ll b,ll &x,ll &y){ if(b==0){ x=1;y=0; return a; } ll r=e...
分类:其他好文   时间:2015-06-12 23:40:56    阅读次数:118
hdu 1576 (A/B)
这个题的关键是求逆元,根据扩展欧几里德算法: 代码如下:#include #include using namespace std; typedef long long LL; const int mod=9973; void exgcd(LL a,LL b,LL &x,LL &y) { if(b==0) { x=1;...
分类:其他好文   时间:2015-05-30 18:20:44    阅读次数:141
poj1061 青蛙的约会 扩展欧几里得
//(x + km)%l == (y + kn)%l //s*l + k(m - n) = y - x //用扩展欧几里得求出k //注意一下k需要为最小正数 #include #include #include using namespace std ; typedef __int64 ll ; ll exgcd(ll a , ll b , ll &x , ll &y) { ...
分类:其他好文   时间:2015-05-09 17:33:38    阅读次数:122
hdu1576 A/B 扩展欧几里得求逆元
//(a/b)%c ==> a%c = (b*k) %c; // k = (a*(b_1))%c ,b_1为b的逆元 #include #include #include using namespace std ; const int mod = 9973 ; typedef __int64 ll; int exgcd(int a ,int b , ll &x ,ll &y) {...
分类:其他好文   时间:2015-05-09 16:39:10    阅读次数:138
[exgcd] zzu oj 10402 C.机器人
题意: Description Dr. Kong 设计的机器人卡尔非常活泼,既能原地蹦,又能跳远。由于受软硬件设计所限,机器人卡尔只能定点跳远。若机器人站在(X,Y)位置,它可以原地蹦,但只可以在(X,Y),(X,-Y),(-X,Y),(-X,-Y),(Y,X),(Y,-X),(-Y,X),(-Y,-X)八个点跳来跳去。 现在,Dr. Kong想在机器人卡尔身上设计一个计数器,记录它...
分类:其他好文   时间:2015-04-30 16:18:32    阅读次数:148
307条   上一页 1 ... 26 27 28 29 30 31 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!