結果

問題 No.25 有限小数
ユーザー yaoshimax
提出日時 2015-02-14 22:27:47
言語 Python2
(2.7.18)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 446 bytes
コンパイル時間 119 ms
コンパイル使用メモリ 6,948 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-15 21:08:30
合計ジャッジ時間 1,409 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

def gcd(A,B):
   if A>B: return gcd(B,A)
   elif B%A==0: return A
   else: return gcd(B%A,A)

N=int(raw_input())
M=int(raw_input())
g = gcd(N,M)
N/=g
M/=g
tM=M

while N%10 ==0:
   N/=10

while tM%10 == 0:
   tM/=10
if tM==1:
   print N%10
   exit()
while tM % 2 == 0:
   tM/=2
if tM==1:
   print 5
   exit()
table = [(i*2)%10 for i in range(10)]
key = N%10
while tM %5 == 0:
   tM/=5
   key = table[key]
if tM==1:
   print key
   exit()
print -1
0