Luogu P6476 [NOI Online #2 提高组]涂色游戏
\(\large{题目链接}\)
\(\\\)
思路:
设\(p_1 > p_2\)且存在这样的\(n,m\)使得 \(m \times p_1 < n \times p_2 < (n+k-1) \times p_2 < (m+1) \times p_1\),那么为了使这个关系尽可能成立,就要使\(n \times p_2 - m \times p_1\)尽可能地小,
根据裴属定理,\(n \times p_2 - m \times p_1\)最小为\(\gcd(p_1, p_2)\)。\(m \times p_1 < n \times p_2 < (n+k-1) \times p_1 < (m+1) \times p_2\)同时除以\(\gcd(p_1, p_2)\),这时\(m \times p_1 + 1 = n \times p_2\),
中间的区域就有\(\dfrac {\dfrac {p_{1}}{\gcd}-2}{\dfrac {p_{2}}{\gcd}}+1\)个连续涂\(p_2\)的格子,与\(k\)比较大小即可。
代码:
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0;
char c = getchar();
for (; !isdigit(c); c = getchar());
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
return x;
}
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
void solve() {
int p1, p2, k;
p1 = read(), p2 = read(), k = read();
if (k == 1) { puts("No"); return; }
if (p1 < p2) swap(p1, p2);
int g = gcd(p1, p2);
p1 /= g, p2 /= g;
((p1 - 2) / p2 + 1 >= k) ? puts("No") : puts("Yes");
}
int main() {
int t = read();
for (; t; --t) solve();
return 0;
}