GCD (Greatest Common Divisor)
来源:互联网 发布:最便宜的域名注册 编辑:程序博客网 时间:2024/05/08 09:28
欧几里德算法(GCD),又称辗转相除法。
//代码一:int gcd(int a, int b){ return b ? gcd(b, a%b):a;}
//代码二:int gcd(int a, int b){while((a %= b) && (b %= a)) ;return a + b;}
练习题:1、Uva 10193 All you need is love //P.S.The Beatles的歌名《All You Need Is Love》。
//扯了一大堆,原来就是求两个数是否互质。。
#include <iostream>#include <cstring>using namespace std;int gcd(int a,int b){return b? gcd(b, a%b):a;}int main(){int a, b;int T;char s[32];int i, n;cin>>T;n=1;while(n<=T){cout<<"Pair #"<<n++<<": ";cin>>s;a = 0;for(i=0;s[i];++i){a =a*2+s[i]-'0';}cin>>s;b = 0;for(i=0;s[i];++i){b =b*2+s[i]-'0';}if(gcd(a,b)==1) cout<<"Love is not all you need!\n";elsecout<<"All you need is love!\n";}return 0;}
- GCD (Greatest Common Divisor)
- GCD Algorithm(Greatest Common Divisor)
- GCD (greatest common divisor)【求最大公约数】
- 求最大公约数Greatest Common Divisor(GCD)
- Euclid Greatest Common Divisor-GCD - 欧几里得 最大公约数
- Greatest Common Divisor(GCD) of Two Numbers
- The greatest common divisor gcd(最大公约数)
- Greatest Common Divisor (GCD) - Euclidean algorithm
- 最大公约数GCD(Greatest Common Divisor)算法小结
- Greatest Greatest Common Divisor
- Greatest Greatest Common Divisor HD5207
- Eculid算法递归地求解GCD(Greatest Common Divisor,最大公约数)
- Greatest common divisor
- The Greatest Common Divisor
- Solving Greatest Common Divisor
- the greatest common divisor
- 最大公约数Greatest Common Divisor
- 最大公约数(greatest common divisor)算法
- linux 信号详解
- 获取成员函数地址3种方法
- ORACLE启动 切换实例命令
- binder驱动之我见
- Map通过key删除value
- GCD (Greatest Common Divisor)
- cocos2d-x 多点触摸
- input 子系统浅析
- HDU2888(二维RMQ)
- axMapControl1 OnMouseWheel 缩放
- hdu1297
- 一个批量安装文件夹下(包括子目录下)全部的Android apk文件批处理脚本
- Android图片分辨率——nodpi,xhdpi,hdpi,mdpi,ldpi
- hadoop Capacity Scheduler解析