結果

問題 No.25 有限小数
ユーザー Mcpu3Mcpu3
提出日時 2019-03-19 23:35:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 5,000 ms
コード長 724 bytes
コンパイル時間 2,136 ms
コンパイル使用メモリ 73,156 KB
実行使用メモリ 56,508 KB
最終ジャッジ日時 2023-10-12 14:57:57
合計ジャッジ時間 7,408 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,052 KB
testcase_01 AC 123 ms
55,992 KB
testcase_02 AC 122 ms
56,400 KB
testcase_03 AC 122 ms
56,004 KB
testcase_04 AC 125 ms
55,936 KB
testcase_05 AC 125 ms
55,848 KB
testcase_06 AC 124 ms
56,272 KB
testcase_07 AC 122 ms
55,592 KB
testcase_08 AC 128 ms
56,508 KB
testcase_09 AC 122 ms
56,236 KB
testcase_10 AC 122 ms
55,916 KB
testcase_11 AC 120 ms
55,904 KB
testcase_12 AC 121 ms
55,856 KB
testcase_13 AC 123 ms
56,240 KB
testcase_14 AC 122 ms
55,984 KB
testcase_15 AC 125 ms
55,776 KB
testcase_16 AC 124 ms
56,492 KB
testcase_17 AC 127 ms
54,236 KB
testcase_18 AC 124 ms
56,172 KB
testcase_19 AC 122 ms
56,028 KB
testcase_20 AC 123 ms
55,844 KB
testcase_21 AC 129 ms
55,752 KB
testcase_22 AC 125 ms
55,732 KB
testcase_23 AC 124 ms
56,056 KB
testcase_24 AC 123 ms
56,172 KB
testcase_25 AC 122 ms
55,784 KB
testcase_26 AC 123 ms
55,984 KB
testcase_27 AC 120 ms
56,028 KB
testcase_28 AC 125 ms
56,052 KB
testcase_29 AC 122 ms
55,988 KB
testcase_30 AC 121 ms
55,636 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