結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,380 KB
testcase_01 AC 43 ms
49,432 KB
testcase_02 AC 43 ms
49,232 KB
testcase_03 AC 43 ms
49,288 KB
testcase_04 AC 44 ms
49,240 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 44 ms
49,396 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 43 ms
49,260 KB
testcase_12 AC 44 ms
49,320 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 44 ms
49,268 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 44 ms
49,244 KB
testcase_20 AC 43 ms
49,236 KB
testcase_21 AC 43 ms
49,272 KB
testcase_22 AC 43 ms
49,536 KB
testcase_23 AC 43 ms
49,196 KB
testcase_24 AC 44 ms
49,332 KB
testcase_25 AC 44 ms
49,412 KB
testcase_26 AC 43 ms
49,280 KB
testcase_27 AC 43 ms
49,296 KB
testcase_28 AC 44 ms
49,648 KB
testcase_29 AC 44 ms
49,332 KB
testcase_30 AC 44 ms
49,340 KB
権限があれば一括ダウンロードができます

ソースコード

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);
            return;
        }
        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