結果

問題 No.25 有限小数
ユーザー ゆるく
提出日時 2014-11-22 02:57:26
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 40 ms / 5,000 ms
コード長 642 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-11-15 21:07:18
合計ジャッジ時間 2,791 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from fractions import Fraction
from copy import deepcopy

a = int(input())
b = int(input())

c = Fraction(a, b)
aa = c.numerator
bb = c.denominator
d = bb
p2 = 0
p5 = 0
while(d % 2 == 0):
  d //= 2
  p2 += 1
while(d % 5 == 0):
  d //= 5
  p5 += 1
if d == 1:
  while(aa % 10 == 0):
    aa //= 10
  aa %= 10
  while(p2 > p5):
    aa = (aa * 5) % 10
    p5 += 1
  while(p5 > p2):
    aa = (aa * 2) % 10
    p2 += 1
  print(aa)
else:
  print(-1)
0