結果

問題 No.25 有限小数
ユーザー uafr_csuafr_cs
提出日時 2017-11-11 10:31:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,550 ms / 5,000 ms
コード長 1,258 bytes
コンパイル時間 2,227 ms
コンパイル使用メモリ 78,900 KB
実行使用メモリ 74,332 KB
最終ジャッジ日時 2024-05-03 16:27:58
合計ジャッジ時間 22,332 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
54,048 KB
testcase_01 AC 118 ms
54,248 KB
testcase_02 AC 113 ms
53,980 KB
testcase_03 AC 113 ms
54,104 KB
testcase_04 AC 107 ms
53,592 KB
testcase_05 AC 118 ms
54,120 KB
testcase_06 AC 104 ms
52,564 KB
testcase_07 AC 103 ms
52,784 KB
testcase_08 AC 114 ms
53,932 KB
testcase_09 AC 117 ms
54,376 KB
testcase_10 AC 114 ms
54,016 KB
testcase_11 AC 105 ms
53,104 KB
testcase_12 AC 101 ms
53,052 KB
testcase_13 AC 115 ms
53,960 KB
testcase_14 AC 103 ms
53,036 KB
testcase_15 AC 99 ms
52,656 KB
testcase_16 AC 126 ms
54,172 KB
testcase_17 AC 129 ms
53,972 KB
testcase_18 AC 119 ms
54,248 KB
testcase_19 AC 2,342 ms
71,492 KB
testcase_20 AC 111 ms
41,336 KB
testcase_21 AC 114 ms
40,332 KB
testcase_22 AC 112 ms
40,256 KB
testcase_23 AC 118 ms
41,392 KB
testcase_24 AC 106 ms
41,184 KB
testcase_25 AC 2,336 ms
61,920 KB
testcase_26 AC 2,368 ms
71,900 KB
testcase_27 AC 2,377 ms
62,016 KB
testcase_28 AC 2,384 ms
74,332 KB
testcase_29 AC 2,380 ms
62,256 KB
testcase_30 AC 2,550 ms
71,868 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>();
		/*
		 * 嘘解法っぽいの投げたら通っちゃった...
		 * 実際、素因数を mod で篩うのを十分やれば
		 *  10 以外の因数が含まれているか分かっちゃうか
		 */
		boolean found = false;
		for(int tt = 0; tt <= 100000; tt++){
			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