gcd算法是用来求两个数最大公约数的算法,他是依靠辗转相除(中国好像叫辗转相减)法来求两个数的最大公约数,别的地方也有很多介绍不做过多赘述,主要提供代码供自己参考. gcd(int a,int b) { ?a:gcd(b,a%b); } 对于拓展gcd,是对方程ax+by=c求解: 就是a mod b=c这个方程求解: 具体看代码,不做过多赘述因为别人已经讲的很详细了,在这里copy一下别人的讲解: 我们其实只需要考虑形如 a • x mod n = 1 的方程.因为,如果能解出这样的方程, a…
进来Bear正在学习巩固并行的基础知识,所以写下这篇基础的有关并行算法的文章. 在讲述两个算法之前,需要明确一些概念性的问题, Race Condition(竞争条件),Situations like this, where two or more processes are reading or writing some shared data and the final result depends on who runs precisely when, are called…