結果
問題 | No.25 有限小数 |
ユーザー |
![]() |
提出日時 | 2021-12-02 15:24:23 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,607 bytes |
コンパイル時間 | 2,055 ms |
コンパイル使用メモリ | 77,308 KB |
実行使用メモリ | 52,504 KB |
最終ジャッジ日時 | 2024-07-05 01:55:59 |
合計ジャッジ時間 | 4,784 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 7 WA * 24 |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); long n = sc.nextLong(); long m = sc.nextLong(); long gcd = getGCD(n, m); m /= gcd; n /= gcd; while (m % 2 == 0) { if (n % 10 > 0) { n *= 10; } m /= 2; n /= 2; } while (m % 5 == 0) { if (n % 10 > 0) { n *= 10; } m /= 5; n /= 5; } if (m > 1) { System.out.println(-1); } while (n % 10 == 0) { n /= 10; } System.out.println(n % 10); } static long getGCD(long x, long y) { if (x % y == 0) { return y; } else { return getGCD(y, x % y); } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }