結果

問題 No.25 有限小数
ユーザー tentententen
提出日時 2021-12-02 15:24:23
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,607 bytes
コンパイル時間 2,242 ms
コンパイル使用メモリ 74,956 KB
実行使用メモリ 51,720 KB
最終ジャッジ日時 2023-09-18 10:18:19
合計ジャッジ時間 4,809 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,224 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 44 ms
49,376 KB
testcase_04 AC 43 ms
49,324 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 44 ms
49,272 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 43 ms
49,216 KB
testcase_23 AC 44 ms
49,788 KB
testcase_24 AC 44 ms
49,316 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
}
0