結果
問題 |
No.25 有限小数
|
ユーザー |
|
提出日時 | 2025-06-12 23:06:56 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 767 bytes |
コンパイル時間 | 352 ms |
コンパイル使用メモリ | 12,032 KB |
実行使用メモリ | 251,068 KB |
最終ジャッジ日時 | 2025-06-12 23:07:17 |
合計ジャッジ時間 | 18,516 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 31 |
ソースコード
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) if len(ans) > 2*10**6: print(-1) exit() rem %= b return ans a,b=map(int,read().split()) print(a,b) 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)