扩展欧几里得算法就是求: ax + by = gcd(a, b)的一组整数解(x, y)一、非递归的实现:首先看a = 60, b = 22的情况:表格左边是欧几里得算法,右边等式计算ax + by = gcd(a, b)的解a = 2 × b + 1616 = a - 2bb = 1× ...
分类:
其他好文 时间:
2014-07-21 09:35:19
阅读次数:
290
int gcd(int n,int m)//n>m
{
//最大公约数
int r;
while(m)
{
r = n%m;
n = m;
m = r;
}
return n;
}
int kgcd(int a,int b)
{
if(!a) return b;
if(!b) retu...
分类:
其他好文 时间:
2014-07-19 23:37:19
阅读次数:
309
刚学习的扩展欧几里得算法,刷个水题
求解 线性不定方程 和 模线性方程
求方程 ax+by=c 或 ax≡c (mod b) 的整数解
1、ax+by=gcd(a,b)的一个整数解:
void ex_gcd(int a,int b,int &d,int &x,int &y)//扩展欧几里得算法
{
if(!b){d=a;x=1;y=0;}
else {ex_gcd(...
分类:
其他好文 时间:
2014-07-19 18:26:00
阅读次数:
226
1 LL Ex_GCD(LL a,LL b,LL &x,LL& y) 2 { 3 if(b==0) 4 { 5 x=1; 6 y=0; 7 return a; 8 } 9 LL g=Ex_GCD(b,a%b,x,y);...
分类:
其他好文 时间:
2014-07-19 17:04:57
阅读次数:
249
UVA 11774 - Doom's Day
题目链接
题意:给定一个3^n*3^m的矩阵,要求每次按行优先取出,按列优先放回,问几次能回复原状
思路:没想到怎么推理,找规律答案是(n + m) / gcd(n, m),在topcoder上看到一个证明,如下:
We can associate at each cell a base 3-number, the log3(R...
分类:
其他好文 时间:
2014-07-19 14:06:19
阅读次数:
220
GCD SUMTime Limit:8000/4000MS (Java/Others)Memory Limit:128000/64000KB (Java/Others)SubmitStatusProblem Description给出N,M执行如下程序:long long ans = 0,ansx ...
分类:
其他好文 时间:
2014-07-19 09:15:30
阅读次数:
234
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2028题目大意:求最小公倍数,用辗转相除法。 1 #include 2 int main () 3 { 4 int gcd(int a,int b); 5 int a,b,n,i,c; ...
分类:
其他好文 时间:
2014-07-18 17:37:40
阅读次数:
305
UVA 10294 - Arif in Dhaka (First Love Part 2)
题目链接
题意:给定n个珠子,t种颜色, 问能组成几个项链和手镯(手镯能翻转,项链不能)
思路:利用Burnside求解,推理出旋转的循环个数是gcd(i, n),翻转的分为奇偶情况考虑
代码:
#include
#include
const int N = 30;
in...
分类:
其他好文 时间:
2014-07-18 15:12:41
阅读次数:
215
UVA 12103 - Leonardo's Notebook
题目链接
题意:给定一个字母置换B,求是否存在A使得A^2=B
思路:任意一个长为 L 的置换的k次幂,会把自己分裂成gcd(L,k) 分, 并且每一份的长度都为 L / gcd(l,k),因此平方对于奇数长度不变,偶数则会分裂成两份长度相同的循环,因此如果B中偶数长度的循环个数不为偶数必然不存在A了
代码:
...
分类:
其他好文 时间:
2014-07-18 15:12:10
阅读次数:
300
GCD为Grand Central Dispatch的缩写。 Grand Central Dispatch (GCD)是Apple开发的一个多核编程的较新的解决方法。在Mac OS X 10.6雪豹中首次推出,并在最近引入到了iOS4.0。 GCD是一个替代诸如NSThread等技术的很高效和强.....
分类:
移动开发 时间:
2014-07-18 12:07:40
阅读次数:
324