結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,064 KB
testcase_01 AC 124 ms
55,660 KB
testcase_02 AC 125 ms
55,820 KB
testcase_03 AC 125 ms
55,764 KB
testcase_04 AC 127 ms
55,664 KB
testcase_05 AC 126 ms
55,964 KB
testcase_06 WA -
testcase_07 AC 125 ms
55,504 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 125 ms
55,792 KB
testcase_12 AC 125 ms
55,860 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 124 ms
55,892 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 125 ms
55,800 KB
testcase_20 AC 124 ms
55,672 KB
testcase_21 AC 126 ms
55,820 KB
testcase_22 AC 125 ms
55,624 KB
testcase_23 AC 124 ms
55,548 KB
testcase_24 AC 127 ms
55,616 KB
testcase_25 AC 125 ms
55,708 KB
testcase_26 AC 126 ms
55,860 KB
testcase_27 AC 125 ms
55,776 KB
testcase_28 AC 125 ms
55,848 KB
testcase_29 AC 127 ms
56,056 KB
testcase_30 AC 126 ms
55,892 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(1024L*1024*1024*1024*1024*1024*4, 625L*625*625*625*625*625));
		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;
		
		long res = n;
		
		while(m%10==0)
			m /= 10;
		
		res %= 1000000000000000000L;
		while(m%2==0){
			res *= 5;
			m /= 2;

			res %= 1000000000000000000L;
		}
		
		
		while(m%5==0){
			res *= 2;
			m /= 5;

			res %= 1000000000000000000L;
		}
			
		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