https://www.hackerrank.com/contests/w7/challenges/die-hard-3

首先,发现c <= max(a, b) 而且 c = aX + bY时有解。然后根据扩展欧几里得算法知道c % gcd(a, b) == 0时有解。

#include <vector>
#include <iostream>

using namespace std;

int gcd(int a, int b) {
	if (a % b == 0) {
		return b;
	} else {
		return gcd(b, a % b);
	}
}

int main() {
	int T;
	cin >> T;
	while (T--) {
		int a, b, c;
		cin >> a >> b >> c;
		int r = gcd(a, b);
		if (c % r == 0 && c <= max(a, b)) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
    return 0;
}

  

相关文章:

  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2021-06-22
  • 2022-12-23
  • 2021-08-27
猜你喜欢
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2021-11-09
  • 2022-01-03
  • 2022-02-07
  • 2022-01-08
相关资源
相似解决方案