1 条题解
-
0
Congruent
若, 则
$$\frac{p_A}{q_A}=\frac{p_B}{q_B} + k \times \frac{p_M}{q_M}, k \in Z $$等式两边同乘, 则有
这个式子等价于
对于上述式子的判断只需要两边取模即可。
然而,这里的乘法有可能超出 long long int 的范围,因此需要一些改进。
我们可以令, 那么需要判断的式子就是.
只需要比较与是否同时为0即可。
import math def gcd(a, b): if b == 0: return a return gcd(b, a % b) def main(): pA, qA, pB, qB, pM, qM = map(int, input().split()) B = qA * qB A = pA * qB - qA * pB common_divisor = gcd(abs(A), abs(B)) A //= common_divisor B //= common_divisor x1 = A * qM x2 = B * pM ans = x1 / x2 res = int(ans) if res == ans: print("Yes") else: print("No") if __name__ == "__main__": main()
- 1
信息
- ID
- 293
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- (无)
- 递交数
- 56
- 已通过
- 9
- 上传者