結果

問題 No.25 有限小数
ユーザー uafr_csuafr_cs
提出日時 2017-11-11 10:14:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,372 ms / 5,000 ms
コード長 1,096 bytes
コンパイル時間 2,007 ms
コンパイル使用メモリ 79,040 KB
実行使用メモリ 72,436 KB
最終ジャッジ日時 2024-05-03 16:27:04
合計ジャッジ時間 22,287 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
54,444 KB
testcase_01 AC 120 ms
53,724 KB
testcase_02 AC 115 ms
54,348 KB
testcase_03 AC 115 ms
54,116 KB
testcase_04 AC 116 ms
54,124 KB
testcase_05 AC 108 ms
52,968 KB
testcase_06 AC 116 ms
54,236 KB
testcase_07 AC 117 ms
53,996 KB
testcase_08 AC 117 ms
54,296 KB
testcase_09 AC 120 ms
54,100 KB
testcase_10 AC 105 ms
52,680 KB
testcase_11 AC 116 ms
54,236 KB
testcase_12 AC 123 ms
54,096 KB
testcase_13 AC 111 ms
52,696 KB
testcase_14 AC 105 ms
54,328 KB
testcase_15 AC 120 ms
54,204 KB
testcase_16 AC 127 ms
53,972 KB
testcase_17 AC 115 ms
54,260 KB
testcase_18 AC 122 ms
54,020 KB
testcase_19 AC 2,340 ms
72,428 KB
testcase_20 AC 120 ms
54,196 KB
testcase_21 AC 122 ms
54,212 KB
testcase_22 AC 114 ms
54,296 KB
testcase_23 AC 113 ms
54,024 KB
testcase_24 AC 114 ms
54,244 KB
testcase_25 AC 2,304 ms
72,292 KB
testcase_26 AC 2,331 ms
72,236 KB
testcase_27 AC 2,346 ms
72,228 KB
testcase_28 AC 2,345 ms
72,316 KB
testcase_29 AC 2,337 ms
72,436 KB
testcase_30 AC 2,372 ms
72,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	public static long MOD = 1000000007;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		BigInteger N = new BigInteger(sc.next());
		BigInteger M = new BigInteger(sc.next());
		
		BigInteger answer = BigInteger.ZERO;
		
		HashSet<BigInteger> already = new HashSet<BigInteger>();
		
		boolean found = false;
		for(int tt = 0; tt <= 100000; tt++){
			//System.out.println(N + "/" + M);
			answer = answer.multiply(BigInteger.TEN);
			answer = answer.add(N.divide(M));
			
			final BigInteger mod = N.mod(M);
			
			if(mod.equals(BigInteger.ZERO)){
				found = true;
				break;
			}
			
			if(already.contains(mod)){
				System.out.println(-1);
				return;
			}
			
			already.add(mod);
			N = mod.multiply(BigInteger.TEN);
		}
		
		if(!found){ System.out.println(-1); return; }
		
		final String output = answer.toString().replace("0", "");
		System.out.println(output.charAt(output.length() - 1));
	}
}
0