結果

問題 No.25 有限小数
ユーザー scache
提出日時 2014-11-15 10:46:18
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 997 bytes
コンパイル時間 3,556 ms
コンパイル使用メモリ 75,028 KB
実行使用メモリ 56,172 KB
最終ジャッジ日時 2024-12-31 10:53:24
合計ジャッジ時間 8,848 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22 WA * 9
権限があれば一括ダウンロードができます

ソースコード

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

		
		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