結果

問題 No.25 有限小数
ユーザー Mcpu3Mcpu3
提出日時 2019-03-19 23:34:14
言語 Java19
(openjdk 21)
結果
AC  
実行時間 124 ms / 5,000 ms
コード長 725 bytes
コンパイル時間 2,139 ms
コンパイル使用メモリ 71,524 KB
実行使用メモリ 56,764 KB
最終ジャッジ日時 2023-10-12 14:55:47
合計ジャッジ時間 7,332 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,880 KB
testcase_01 AC 118 ms
55,744 KB
testcase_02 AC 117 ms
56,024 KB
testcase_03 AC 120 ms
56,472 KB
testcase_04 AC 120 ms
55,984 KB
testcase_05 AC 121 ms
56,172 KB
testcase_06 AC 124 ms
56,376 KB
testcase_07 AC 120 ms
56,136 KB
testcase_08 AC 121 ms
56,448 KB
testcase_09 AC 122 ms
56,440 KB
testcase_10 AC 122 ms
55,948 KB
testcase_11 AC 119 ms
56,264 KB
testcase_12 AC 116 ms
56,232 KB
testcase_13 AC 123 ms
55,820 KB
testcase_14 AC 118 ms
55,888 KB
testcase_15 AC 120 ms
55,888 KB
testcase_16 AC 120 ms
56,324 KB
testcase_17 AC 121 ms
56,204 KB
testcase_18 AC 120 ms
54,768 KB
testcase_19 AC 117 ms
56,188 KB
testcase_20 AC 119 ms
55,696 KB
testcase_21 AC 120 ms
56,404 KB
testcase_22 AC 120 ms
56,764 KB
testcase_23 AC 122 ms
56,224 KB
testcase_24 AC 117 ms
55,868 KB
testcase_25 AC 119 ms
56,244 KB
testcase_26 AC 122 ms
55,652 KB
testcase_27 AC 118 ms
55,700 KB
testcase_28 AC 119 ms
55,696 KB
testcase_29 AC 120 ms
55,672 KB
testcase_30 AC 122 ms
56,208 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