結果

問題 No.25 有限小数
ユーザー scachescache
提出日時 2014-11-15 11:05:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 115 ms / 5,000 ms
コード長 943 bytes
コンパイル時間 3,369 ms
コンパイル使用メモリ 74,580 KB
実行使用メモリ 41,656 KB
最終ジャッジ日時 2024-04-27 17:07:08
合計ジャッジ時間 6,971 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
41,096 KB
testcase_01 AC 109 ms
41,196 KB
testcase_02 AC 106 ms
41,348 KB
testcase_03 AC 109 ms
41,404 KB
testcase_04 AC 103 ms
40,832 KB
testcase_05 AC 102 ms
39,844 KB
testcase_06 AC 107 ms
40,096 KB
testcase_07 AC 113 ms
41,324 KB
testcase_08 AC 109 ms
41,656 KB
testcase_09 AC 99 ms
40,100 KB
testcase_10 AC 94 ms
39,688 KB
testcase_11 AC 111 ms
40,940 KB
testcase_12 AC 111 ms
41,132 KB
testcase_13 AC 101 ms
40,084 KB
testcase_14 AC 99 ms
40,200 KB
testcase_15 AC 101 ms
40,092 KB
testcase_16 AC 106 ms
41,132 KB
testcase_17 AC 106 ms
41,292 KB
testcase_18 AC 109 ms
41,376 KB
testcase_19 AC 109 ms
41,096 KB
testcase_20 AC 107 ms
41,224 KB
testcase_21 AC 111 ms
41,072 KB
testcase_22 AC 105 ms
40,768 KB
testcase_23 AC 113 ms
40,992 KB
testcase_24 AC 99 ms
40,092 KB
testcase_25 AC 95 ms
39,964 KB
testcase_26 AC 100 ms
40,040 KB
testcase_27 AC 108 ms
41,080 KB
testcase_28 AC 104 ms
41,196 KB
testcase_29 AC 109 ms
41,192 KB
testcase_30 AC 115 ms
41,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


import java.util.Scanner;

/**
 * yukicoder no.25
 * @author scache
 *
 */
public class FiniteDecimal {
	public static void main(String[] args) {
		FiniteDecimal p = new FiniteDecimal();
	}

	public FiniteDecimal() {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long m = sc.nextLong();
		
		System.out.println(solve(n, m));
	
	}

	public int solve(long n, long m) {
		long g = gcd(n, m);
		m /= g;
		n /= g;
		
		while(n%10 == 0)
			n /= 10;
		
//		System.out.println(n +" " + n +" "+m);
		long res = n % 10;

		
		while(m%10==0)
			m /= 10;
		
		while(m%2==0){
			res *= 5;
			res %= 1000000000000000000L;
			m /= 2;
		}
		while(m%5==0){
			res *= 2;
			res %= 1000000000000000000L;
			m /= 5;
		}
			
		if(m==1)
			return (int)(res%10);
		else
			return -1;
	}
	
	private long gcd(long a, long b){
		if(b==0)
			return a;
		else
			return gcd(b, a%b);
	}
}
0