結果

問題 No.25 有限小数
ユーザー tentententen
提出日時 2023-06-12 15:39:11
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,300 bytes
コンパイル時間 4,124 ms
コンパイル使用メモリ 86,860 KB
実行使用メモリ 49,892 KB
最終ジャッジ日時 2023-09-02 10:18:22
合計ジャッジ時間 7,244 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,620 KB
testcase_01 AC 45 ms
49,892 KB
testcase_02 AC 44 ms
47,968 KB
testcase_03 AC 44 ms
49,484 KB
testcase_04 AC 45 ms
49,716 KB
testcase_05 AC 45 ms
49,384 KB
testcase_06 AC 44 ms
49,792 KB
testcase_07 AC 44 ms
49,380 KB
testcase_08 AC 44 ms
47,436 KB
testcase_09 AC 45 ms
49,424 KB
testcase_10 AC 44 ms
49,420 KB
testcase_11 AC 46 ms
49,380 KB
testcase_12 WA -
testcase_13 AC 46 ms
49,356 KB
testcase_14 AC 45 ms
49,424 KB
testcase_15 AC 46 ms
49,428 KB
testcase_16 AC 45 ms
49,720 KB
testcase_17 AC 45 ms
49,384 KB
testcase_18 AC 44 ms
49,504 KB
testcase_19 AC 46 ms
49,360 KB
testcase_20 AC 45 ms
49,356 KB
testcase_21 AC 45 ms
49,404 KB
testcase_22 AC 45 ms
49,424 KB
testcase_23 AC 45 ms
49,452 KB
testcase_24 AC 44 ms
49,624 KB
testcase_25 AC 45 ms
49,384 KB
testcase_26 AC 45 ms
49,704 KB
testcase_27 AC 46 ms
49,352 KB
testcase_28 AC 46 ms
49,484 KB
testcase_29 AC 46 ms
49,484 KB
testcase_30 AC 46 ms
49,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

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);
        n /= gcd;
        m /= gcd;
        while (m % 10 == 0) {
            m /= 10;
        }
        while (n % 10 == 0) {
            n /= 10;
        }
        while (m % 2 == 0) {
            m /= 2;
            n *= 5;
            while (n % 10 == 0) {
                n /= 10;
            }
            n %= 10;
        }
        while (m % 5 == 0) {
            m /= 5;
            n *= 2;
            while (n % 10 == 0) {
                n /= 10;
            }
            n %= 10;
        }
        if (m == 1) {
            System.out.println(n);
        } else {
            System.out.println(-1);
        }
    }
    
    
    static long getGCD(long x, long y) {
        if (y == 0) {
            return x;
        } else {
            return getGCD(y, x % y);
        }
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0