hdu 1722

注解:很难受的一道题,一看这道题就有点小学奥数的感觉,我恨数学。。。实在找不出规律,直接扔上一位老哥的数学证明:数学公式

代码如下(我是弱鸡):

#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

int fun(int x, int y)
{
	int tmp;
	if (x < y)
	{
		tmp = x;
		x = y;
		y = tmp;
	}
	while (y)
	{
		tmp = x % y;
		x = y;
		y = tmp;
	}

	return x;
}


int main()
{
	int m, n, ans;

	while (cin >> m >> n)
		cout << m + n - fun(m, n) << endl;

	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40058686/article/details/79963028
今日推荐