結果

問題 No.25 有限小数
ユーザー uafr_csuafr_cs
提出日時 2017-11-11 10:14:45
言語 Java19
(openjdk 21)
結果
AC  
実行時間 2,460 ms / 5,000 ms
コード長 1,096 bytes
コンパイル時間 2,330 ms
コンパイル使用メモリ 74,780 KB
実行使用メモリ 74,176 KB
最終ジャッジ日時 2023-08-16 07:26:13
合計ジャッジ時間 23,308 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,704 KB
testcase_01 AC 115 ms
55,792 KB
testcase_02 AC 115 ms
55,760 KB
testcase_03 AC 118 ms
56,132 KB
testcase_04 AC 117 ms
55,580 KB
testcase_05 AC 113 ms
55,580 KB
testcase_06 AC 117 ms
56,044 KB
testcase_07 AC 116 ms
55,644 KB
testcase_08 AC 118 ms
55,928 KB
testcase_09 AC 117 ms
56,100 KB
testcase_10 AC 117 ms
55,472 KB
testcase_11 AC 119 ms
56,048 KB
testcase_12 AC 117 ms
55,648 KB
testcase_13 AC 117 ms
54,060 KB
testcase_14 AC 118 ms
55,760 KB
testcase_15 AC 116 ms
55,968 KB
testcase_16 AC 119 ms
55,868 KB
testcase_17 AC 118 ms
56,172 KB
testcase_18 AC 118 ms
55,796 KB
testcase_19 AC 2,388 ms
73,808 KB
testcase_20 AC 116 ms
55,728 KB
testcase_21 AC 115 ms
56,000 KB
testcase_22 AC 119 ms
55,708 KB
testcase_23 AC 115 ms
55,552 KB
testcase_24 AC 116 ms
55,676 KB
testcase_25 AC 2,413 ms
73,684 KB
testcase_26 AC 2,400 ms
73,396 KB
testcase_27 AC 2,419 ms
73,528 KB
testcase_28 AC 2,435 ms
73,944 KB
testcase_29 AC 2,436 ms
74,176 KB
testcase_30 AC 2,460 ms
73,548 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