시도1: 뭔가 그려보니 최대공약수로 구할 수 있을 것 같았다
시도2: 아 음수에서 틀린듯 고쳤다 -> 그런데도 틀렸다.. 왜.....
시도3: 아.. 이게 gcd가 무조건 최소가 아니구나!!!
재밌었다. 처음에 gcd 생각하고 크.. 했었는데 생각해볼 부분이 하나 더 남아있었구나.
출제자의 도움 받아서 품
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <bitset>
#include <stdio.h>
#include <math.h>
#include <sstream>
#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using iis = pair<int, string>;
using ii64 = pair<i64, i64>;
using iii = tuple<int, int, int>;
i64 gcd(i64 a, i64 b) {
if (b == 0)
return a;
return gcd(b, a%b);
}
int main()
{
i64 n, m;
scanf("%lld %lld", &n, &m);
n = abs(n);
m = abs(m);
printf("%lld\n", min(gcd(max(n, m), min(n, m)), 2ll));
return 0;
}
'백준' 카테고리의 다른 글
18870 좌표 압축 (0) | 2021.12.24 |
---|---|
16139 인간-컴퓨터 상호작용 (0) | 2021.12.23 |
11725 트리의 부모 찾기 (0) | 2021.12.23 |
11724 연결 요소의 개수 (0) | 2021.12.23 |
10819 차이를 최대로 (0) | 2021.12.23 |