結果

問題 No.186 中華風 (Easy)
ユーザー snukesnuke
提出日時 2015-04-20 15:58:28
言語 Python2
(2.7.18)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 704 bytes
コンパイル時間 744 ms
コンパイル使用メモリ 6,632 KB
実行使用メモリ 6,068 KB
最終ジャッジ日時 2023-09-18 01:09:24
合計ジャッジ時間 2,245 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,068 KB
testcase_01 AC 11 ms
5,856 KB
testcase_02 AC 11 ms
5,828 KB
testcase_03 AC 11 ms
5,920 KB
testcase_04 AC 11 ms
6,000 KB
testcase_05 AC 11 ms
5,992 KB
testcase_06 AC 12 ms
5,912 KB
testcase_07 AC 11 ms
6,020 KB
testcase_08 AC 11 ms
5,884 KB
testcase_09 AC 11 ms
5,920 KB
testcase_10 AC 11 ms
5,900 KB
testcase_11 AC 11 ms
5,848 KB
testcase_12 AC 11 ms
6,020 KB
testcase_13 AC 11 ms
5,852 KB
testcase_14 AC 11 ms
5,916 KB
testcase_15 AC 11 ms
5,856 KB
testcase_16 AC 11 ms
5,868 KB
testcase_17 AC 11 ms
5,996 KB
testcase_18 WA -
testcase_19 AC 11 ms
5,960 KB
testcase_20 AC 11 ms
6,004 KB
testcase_21 AC 11 ms
5,908 KB
testcase_22 AC 11 ms
5,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = 3
a = 0
b = 1

def extgcd(x,y):
  if y == 0: return (x,1,0)
  g,a,b = extgcd(y,x%y);
  return (g,b,a-x//y*b)

def factor(x):
  r = []
  i = 2
  while i*i < x:
    while x%i == 0:
      r.append(i)
      x /= i
    i += 1
  if x != 1: r.append(x)
  return r

def f(x,p):
  r = 1
  while x%p == 0:
    x /= p
    r *= p
  return r

def fail():
  print -1
  exit(0)

for ti in xrange(n):
  na,nb = map(int,raw_input().split())
  g = extgcd(b,nb)[0]
  if a%g != na%g: fail()
  for p in factor(g):
    p1 = f(b,p)
    p2 = f(nb,p)
    if p1 < p2:
      b /= p1
      a %= b
    else:
      nb /= p2
      na %= nb
  x,y = extgcd(b,nb)[1:]
  a = x*b*na + y*nb*a
  b *= nb
  a %= b

if a == 0: a = b
print a
0