题解 SP27561

STLSTLSTL

看到题目的第一反应:啊啊啊啊啊?内存限制:1.46GB,什么鬼啊!
我心想肯定是超大暴力了。

然而鼠标滚轮往下……

WTF?求三个数的最大公因数???

再看上面1.46GB?

求三个数的最大公因数???

正解

首先想了一下,最大公因数?

辗转相除?

1
2
3
4
5
6
7
8
9
10
11
int zhanzhuan(int x, int y)
{
int z = y;
while(x%y!=0)
{
z = x%y;
x = y;
y = z;
}
return z;
}

旁边的小X坐不住了:“你或许可以了解一下__gcd!”;

经过了我的百度大法……

1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
ios::sync_with_stdio(false);//嘿嘿
int a,b,c;
cin>>a>>b>>c;
cout<<__gcd(__gcd(a,b),__gcd(b,c));//直接输出(STL大法好!)
return 0;//Ohhhhhhhhh!!!
}

然后这题就这么水过去了……