您的位置:首页 > 其它

花式GCD

2016-04-22 08:34 211 查看
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<math.h>

using namespace std;

int gcd(int a,int b)
{
return b?gcd(b,a%b):a;
}
int gcd1( int a, int b)
{
int r;
while(b>0)
{
r=a%b;
a=b;
b=r;
}
return a;
}
int gcd2(int a,int b)
{
while(b^=a^=b^=a%=b);
return a;
}
int main()
{
int a,b;
while (scanf("%d,%d",&a,&b)!=EOF) printf("%d\n",gcd(a,b));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: