結果

問題 No.25 有限小数
ユーザー scachescache
提出日時 2014-11-15 10:43:36
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 979 bytes
コンパイル時間 3,306 ms
コンパイル使用メモリ 72,076 KB
実行使用メモリ 56,200 KB
最終ジャッジ日時 2023-08-30 03:41:28
合計ジャッジ時間 8,768 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,868 KB
testcase_01 AC 129 ms
56,168 KB
testcase_02 AC 127 ms
55,856 KB
testcase_03 AC 128 ms
55,836 KB
testcase_04 AC 127 ms
56,192 KB
testcase_05 AC 128 ms
56,004 KB
testcase_06 AC 128 ms
55,964 KB
testcase_07 AC 131 ms
56,112 KB
testcase_08 AC 128 ms
55,860 KB
testcase_09 AC 132 ms
55,932 KB
testcase_10 AC 130 ms
55,804 KB
testcase_11 AC 129 ms
55,732 KB
testcase_12 AC 131 ms
55,508 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 129 ms
55,536 KB
testcase_16 WA -
testcase_17 AC 127 ms
55,980 KB
testcase_18 AC 127 ms
55,768 KB
testcase_19 AC 127 ms
53,956 KB
testcase_20 AC 131 ms
55,704 KB
testcase_21 AC 131 ms
55,964 KB
testcase_22 AC 127 ms
55,772 KB
testcase_23 AC 127 ms
55,920 KB
testcase_24 AC 127 ms
55,708 KB
testcase_25 AC 127 ms
56,200 KB
testcase_26 AC 129 ms
55,916 KB
testcase_27 AC 130 ms
55,536 KB
testcase_28 AC 129 ms
55,528 KB
testcase_29 AC 129 ms
55,784 KB
testcase_30 AC 127 ms
55,536 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;
			
//			System.out.println(res);
		}
		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