結果
問題 |
No.25 有限小数
|
ユーザー |
|
提出日時 | 2025-06-12 21:35:45 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
MLE
|
実行時間 | - |
コード長 | 683 bytes |
コンパイル時間 | 552 ms |
コンパイル使用メモリ | 12,160 KB |
実行使用メモリ | 624,656 KB |
最終ジャッジ日時 | 2025-06-12 21:37:51 |
合計ジャッジ時間 | 8,356 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 MLE * 1 -- * 11 |
ソースコード
import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline def find_frac(a, b): if a==0: return '0' ans = '-' if (a<0)^(b<0) else '' a=abs(a);b=abs(b) ans+=str(a//b) if a%b==0: return ans ans+='.' seen={} rem=a%b while rem: if rem in seen: ans=ans[:seen[rem]] + '(' + ans[seen[rem]:] + ')' break seen[rem]=len(ans) rem*=10 ans += str(rem//b) rem %= b return ans a,b=map(int,read().split()) s=find_frac(a,b) if '(' in s: print(-1) else: for i in range(len(s)-1,-1,-1): if s[i]!='0': print(s[i]) break else: print(-1)