結果

問題 No.25 有限小数
ユーザー Mcpu3Mcpu3
提出日時 2019-03-19 23:30:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 722 bytes
コンパイル時間 2,050 ms
コンパイル使用メモリ 72,236 KB
実行使用メモリ 58,420 KB
最終ジャッジ日時 2023-10-12 14:50:04
合計ジャッジ時間 7,390 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,776 KB
testcase_01 AC 119 ms
55,796 KB
testcase_02 AC 121 ms
55,724 KB
testcase_03 AC 123 ms
56,240 KB
testcase_04 AC 126 ms
55,940 KB
testcase_05 AC 125 ms
55,952 KB
testcase_06 AC 126 ms
56,308 KB
testcase_07 AC 123 ms
56,096 KB
testcase_08 AC 123 ms
55,824 KB
testcase_09 AC 126 ms
56,264 KB
testcase_10 AC 121 ms
55,984 KB
testcase_11 AC 120 ms
55,744 KB
testcase_12 AC 126 ms
56,080 KB
testcase_13 AC 124 ms
58,420 KB
testcase_14 AC 127 ms
56,264 KB
testcase_15 AC 124 ms
55,696 KB
testcase_16 AC 126 ms
56,088 KB
testcase_17 AC 126 ms
54,024 KB
testcase_18 AC 126 ms
54,224 KB
testcase_19 AC 128 ms
55,948 KB
testcase_20 AC 124 ms
55,784 KB
testcase_21 AC 128 ms
55,948 KB
testcase_22 AC 125 ms
56,052 KB
testcase_23 AC 125 ms
56,096 KB
testcase_24 AC 125 ms
55,676 KB
testcase_25 AC 126 ms
55,956 KB
testcase_26 AC 124 ms
55,996 KB
testcase_27 AC 123 ms
55,772 KB
testcase_28 AC 122 ms
53,908 KB
testcase_29 AC 122 ms
53,416 KB
testcase_30 AC 125 ms
55,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigDecimal;
import java.util.Scanner;

class Main {
	static long gcd(long a, long b) {
		return b != 0 ? gcd(b, a % b) : a;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong(), M = sc.nextLong();
		sc.close();
		long tmp1 = gcd(N, M);
		N /= tmp1;
		M /= tmp1;
		tmp1 = M;
		while (tmp1 % 2 == 0) tmp1 /= 2;
		while (tmp1 % 5 == 0) tmp1 /= 5;
		if (tmp1 == 1) {
			BigDecimal tmp2 = new BigDecimal(N), tmp3 = new BigDecimal(M);
			String tmp4 = tmp2.divide(tmp3).toPlainString();
			int i = tmp4.length() - 1;
			while (tmp4.charAt(i) == '0') --i;
			System.out.print(tmp4.charAt(i));
		}
		else System.out.print(-1);
	}
}
0