結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2020-01-15 09:13:26 |
| 言語 | Java (openjdk 23) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 964 bytes |
| コンパイル時間 | 3,602 ms |
| コンパイル使用メモリ | 76,592 KB |
| 実行使用メモリ | 700,488 KB |
| 最終ジャッジ日時 | 2024-12-31 00:48:31 |
| 合計ジャッジ時間 | 49,864 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 TLE * 6 MLE * 7 |
ソースコード
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger n = new BigInteger(sc.next());
BigInteger m = new BigInteger(sc.next());
HashSet<BigInteger> set = new HashSet<>();
while (true) {
BigInteger mod = n.mod(m);
if (mod.equals(BigInteger.ZERO)) {
System.out.println(getLastNum(n.divide(m)));
return;
}
n = mod;
if (set.contains(n)) {
System.out.println(-1);
return;
}
set.add(n);
n = n.multiply(BigInteger.TEN);
}
}
static long getLastNum(BigInteger b) {
long x = b.longValue();
while (x > 0) {
if (x % 10 != 0) {
return x % 10;
}
x /= 10;
}
return 0;
}
}
htensai