結果

問題 No.25 有限小数
ユーザー リチウムリチウム
提出日時 2014-11-17 21:41:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 1,038 bytes
コンパイル時間 2,150 ms
コンパイル使用メモリ 73,384 KB
実行使用メモリ 56,220 KB
最終ジャッジ日時 2023-08-09 22:50:26
合計ジャッジ時間 7,428 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,732 KB
testcase_01 AC 126 ms
55,364 KB
testcase_02 AC 127 ms
55,320 KB
testcase_03 AC 124 ms
55,744 KB
testcase_04 AC 125 ms
55,428 KB
testcase_05 AC 125 ms
56,220 KB
testcase_06 AC 124 ms
55,220 KB
testcase_07 AC 124 ms
55,384 KB
testcase_08 AC 125 ms
55,932 KB
testcase_09 AC 125 ms
55,412 KB
testcase_10 AC 126 ms
53,356 KB
testcase_11 AC 126 ms
55,436 KB
testcase_12 AC 127 ms
55,576 KB
testcase_13 AC 126 ms
55,468 KB
testcase_14 AC 126 ms
55,608 KB
testcase_15 AC 127 ms
55,396 KB
testcase_16 AC 125 ms
55,360 KB
testcase_17 AC 126 ms
55,488 KB
testcase_18 AC 125 ms
55,828 KB
testcase_19 AC 126 ms
55,876 KB
testcase_20 AC 125 ms
55,448 KB
testcase_21 AC 127 ms
55,720 KB
testcase_22 AC 126 ms
55,212 KB
testcase_23 AC 125 ms
55,584 KB
testcase_24 AC 124 ms
55,604 KB
testcase_25 AC 125 ms
55,448 KB
testcase_26 AC 124 ms
55,248 KB
testcase_27 AC 125 ms
55,232 KB
testcase_28 AC 125 ms
55,536 KB
testcase_29 AC 125 ms
55,712 KB
testcase_30 AC 124 ms
55,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	static long GCD(long a, long b) { //最大公約数
		if (a % b == 0 || b % a == 0) {
			return Math.min(a, b);
		} else {
			return GCD(a % b, b % a);
		}
	}
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong();
		long m=sc.nextLong();
		long g=GCD(n,m);
		n/=g;
		m/=g;
		if(m==1){
			while(n%10==0){
				n/=10;
			}
			System.out.println(n%10);
			return;
		}
		int two=0;
		int five=0;
		boolean next=false;
		long c=m;
		do{
			next=false;
			if(c%2==0){
				c/=2;
				two++;
				next=true;
			}
			if(c%5==0){
				c/=5;
				five++;
				next=true;
			}
		}while(next);
		
		int N=(int)(n%10);
		
		if(c!=1 || (two==0 && five==0)){
			System.out.println(-1);
			return;
		}
		else if(two>0 && five>0)System.out.println(N);
		
		else if(two>0)System.out.println(5);
		
		else{
			int x=0;
			while(x<five){
				N*=2;
				N%=10;
				x++;
			}
			System.out.println(N);
		}
		
		
	}}
0