結果
| 問題 | No.25 有限小数 |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-10-22 17:00:24 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 60 ms / 5,000 ms |
| コード長 | 1,155 bytes |
| 記録 | |
| コンパイル時間 | 1,657 ms |
| コンパイル使用メモリ | 82,688 KB |
| 実行使用メモリ | 46,872 KB |
| 最終ジャッジ日時 | 2026-04-03 04:12:37 |
| 合計ジャッジ時間 | 4,492 ms |
|
ジャッジサーバーID (参考情報) |
judge5_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
long m = sc.nextLong();
long gcd = getGCD(n, m);
n /= gcd;
m /= gcd;
long x = m;
int twoCount = 0;
while (x % 2 == 0){
x /= 2;
twoCount++;
}
int fiveCount = 0;
while (x % 5 == 0) {
x /= 5;
fiveCount++;
}
if (x != 1) {
System.out.println(-1);
return;
}
while (n % 10 == 0) {
n /= 10;
}
n %= 10;
if (twoCount > fiveCount) {
System.out.println(5);
} else {
fiveCount -= twoCount;
for (int i = 0; i < fiveCount; i++) {
n *= 10;
n /= 5;
n %= 10;
}
System.out.println(n);
}
}
static long getGCD(long x, long y) {
if (x % y == 0) {
return y;
} else {
return getGCD(y, x % y);
}
}
}
tenten