음.. 최대공약수 같은데..? 왜인지는 증명을 못하겠고..?
때려맞췄는데 맞았고...?
댓글로 증명해주신 분이 계셨습니다! 야호
a,b,c가 정수일 때 ax+by=c인 정수 x, y가 존재할 필요충분조건은 c % gcd(a,b)==0가 돼서 최대공약수를 구하면 된다.... 오.....
이걸 베주 항등식이라고 하는데... a, b가 정수이고 d가 a, b의 최대공약수중 하나라고 하면 ma + mb = d가 성립한다.... 오.. 수학..
#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>
#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 (a % b == 0)
return b;
return gcd(b, a%b);
}
void solve() {
i64 a, b, c;
scanf("%lld %lld %lld", &a, &b, &c);
if (c > a && c > b) {
printf("NO\n");
return;
}
if (a < b)
swap(a, b);
int gcdv = gcd(a, b);
if (c % gcdv == 0) {
printf("YES\n");
return;
}
printf("NO\n");
return;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
solve();
}
return 0;
}
'백준' 카테고리의 다른 글
1907 탄소 화합물 (0) | 2021.08.08 |
---|---|
1783 병든 나이트 (0) | 2021.08.07 |
1676 팩토리얼 0의 개수 (0) | 2021.08.07 |
1002 터렛 (0) | 2021.08.05 |
1015 수열 정렬 (0) | 2021.08.04 |