結果
問題 | No.186 中華風 (Easy) |
ユーザー | ctyl_0 |
提出日時 | 2015-12-04 05:54:43 |
言語 | PyPy2 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,842 bytes |
コンパイル時間 | 363 ms |
コンパイル使用メモリ | 77,312 KB |
実行使用メモリ | 76,032 KB |
最終ジャッジ日時 | 2024-09-14 12:29:35 |
合計ジャッジ時間 | 3,144 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 88 ms
75,392 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 86 ms
75,520 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 86 ms
75,776 KB |
testcase_20 | AC | 86 ms
75,392 KB |
testcase_21 | AC | 87 ms
75,648 KB |
testcase_22 | AC | 86 ms
75,648 KB |
ソースコード
def pow_mod(a, b, m): ret = 1 while b > 0: if b & 1: ret = ret * a % m a = a * a % m b >>= 1 return ret def gcd(p, q): if q == 0: return p return gcd(q, p % q) def ext_gcd(p, q): # return gcd, (x, y) which satisfies px + qy = 1 if q == 0: return (p, 1, 0) g, y, x = ext_gcd(q, p % q) return (g, x, y - (p // q) * x) def inv(p, q): # return p^(-1) mod q when (p, q) is co-prime g, x, y = ext_gcd(p, q) x %= q if x < 0: x += q return x def garner(X, M, op = 1): # C: (X, Y) M: modulo # list up primes lower than 40000 prime_sup = 30 primes = [] is_prime = [0] * prime_sup for i in xrange(2, prime_sup): if is_prime[i] == 0: primes.append([i, 0]) j = i ** 2 while j < prime_sup: is_prime[j] = i j += i for i in xrange(len(X)): y = X[i][1] for j in xrange(len(primes)): cnt = 0 while (y % primes[j][0] == 0): y /= primes[j][0] cnt += 1 primes[j][1] = max(primes[j][1], cnt) if y > 1: primes.append([y, 1]) for prime in primes[:][:]: if prime[1] == 0: primes.remove(prime) # op = 0 if op == 0: ret = int(1) for i in xrange(len(primes)): ret *= pow_mod(primes[i][0], primes[i][1], M) ret %= M return ret # Does the equation have solutoion? for i in range(len(X)): for j in range(i + 1, len(X)): g = gcd(X[i][1], X[j][1]) if X[i][0] % g != X[j][0] % g: return -1 # reguralization prime_check = [0] * len(primes) for i in xrange(len(X)): for j in xrange(len(primes)): if X[i][1] % pow_mod(primes[j][0], primes[j][1], M) == 0 and prime_check[j] == 0: prime_check[j] = 1 else: while X[i][1] % primes[j][0] == 0: X[i][1] /= primes[j][0] X[i][0] %= X[i][1] X.sort(key = lambda x: (x[1])) # garner's algorithm for i in xrange(len(X)): for j in xrange(i): k = X[i][0] - X[j][0] if k < 0: k += X[i][1] X[i][0] = k * inv(X[j][1], X[i][1]) % X[i][1] ret = int(0) for i in reversed(xrange(len(X))): ret = (ret * X[i][1] + X[i][0]) % M return ret # N = int(input()) Z = [] zero = True mod = int(1e9 + 7) for i in xrange(3): Z.append(map(int, raw_input().strip().split(" "))) zero &= (Z[i][0] == 0) if zero == True: print garner(Z, mod, 0) else: print garner(Z, mod, 1)