51nod 1011 最大公约数GCD
生活随笔
收集整理的這篇文章主要介紹了
51nod 1011 最大公约数GCD
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
輸入2個(gè)正整數(shù)A,B,求A與B的最大公約數(shù)。 ?收起
代碼: #include <iostream> #include <cstdio> #include <cmath> #define MAX 50000 #define PI 3.1415926 using namespace std; int gcd(int a,int b) {while(b ^= a ^= b ^= a %= b);return a; } int main() {int a,b;scanf("%d%d",&a,&b);printf("%d",gcd(a,b)); }
輸入
2個(gè)數(shù)A,B,中間用空格隔開(kāi)。(1<= A,B <= 10^9)輸出
輸出A與B的最大公約數(shù)。輸入樣例
30 105輸出樣例
15代碼: #include <iostream> #include <cstdio> #include <cmath> #define MAX 50000 #define PI 3.1415926 using namespace std; int gcd(int a,int b) {while(b ^= a ^= b ^= a %= b);return a; } int main() {int a,b;scanf("%d%d",&a,&b);printf("%d",gcd(a,b)); }
?
轉(zhuǎn)載于:https://www.cnblogs.com/8023spz/p/10015291.html
總結(jié)
以上是生活随笔為你收集整理的51nod 1011 最大公约数GCD的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Kali学习笔记31:目录遍历漏洞、文件
- 下一篇: HTML 转 PDF 之 wkhtmlt