0w1

Extended GCD

POJ 2115 C Looooops

Problem Description: You have a for loop that looks like this: for (value_type i = A; i != B; i += C) ; , where value_type is K-bits unsigned integer data type. You want to know whether the loop will reach an end, and if it will, the numbe…

CFR 806 A. Success Rate ( Math, Extended GCD )

Problem - A - Codeforces題意: 你現在寫了 y 個題目,答對了 x 個。你想知道你最少要再寫幾題才能有答對比率 p / q。若無解輸出 -1。制約: The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Each of the next t l…

POJ 1006 Biorhythms ( CRT, ExtGCD )

1006 -- Biorhythms題意: 細節不好說明,但總之給 p, i, e, d,滿足聯立模方程式: ( x + d ) % 23 = p ( x + d ) % 28 = e ( x + d ) % 33 = i 求 x。解法: 就是一個中國剩餘定理模板。28 非質數,如果要用尤拉定理搞要先求 phi 函數才能求模逆元,但最近…

CFR 7 C. Line ( Extgcd, Math )

http://codeforces.com/contest/7/problem/C題意: 給一個方程式 Ax + By + C = 0,找一組整數 ( x, y ) 在該直線上。或者判斷不存在。解法: 先用 ext_gcd 判斷 Ax + By = gcd( A, B ) 時的 x, y 分別是多少。 ext_gcd 要背!不懂還是要硬背!( 我總是想不…