結果

問題 No.25 有限小数
ユーザー リチウムリチウム
提出日時 2014-11-17 21:41:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 1,038 bytes
コンパイル時間 2,068 ms
コンパイル使用メモリ 76,724 KB
実行使用メモリ 41,692 KB
最終ジャッジ日時 2024-04-27 17:07:17
合計ジャッジ時間 6,998 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
41,068 KB
testcase_01 AC 130 ms
41,436 KB
testcase_02 AC 133 ms
41,120 KB
testcase_03 AC 125 ms
40,864 KB
testcase_04 AC 131 ms
41,300 KB
testcase_05 AC 134 ms
41,372 KB
testcase_06 AC 129 ms
41,220 KB
testcase_07 AC 128 ms
41,452 KB
testcase_08 AC 126 ms
40,208 KB
testcase_09 AC 114 ms
41,296 KB
testcase_10 AC 129 ms
41,136 KB
testcase_11 AC 130 ms
41,500 KB
testcase_12 AC 129 ms
41,140 KB
testcase_13 AC 127 ms
40,968 KB
testcase_14 AC 129 ms
41,372 KB
testcase_15 AC 128 ms
41,140 KB
testcase_16 AC 125 ms
41,440 KB
testcase_17 AC 128 ms
41,284 KB
testcase_18 AC 128 ms
41,404 KB
testcase_19 AC 132 ms
41,588 KB
testcase_20 AC 131 ms
41,392 KB
testcase_21 AC 128 ms
41,464 KB
testcase_22 AC 131 ms
41,460 KB
testcase_23 AC 130 ms
41,280 KB
testcase_24 AC 115 ms
41,388 KB
testcase_25 AC 116 ms
40,000 KB
testcase_26 AC 130 ms
41,692 KB
testcase_27 AC 115 ms
41,116 KB
testcase_28 AC 125 ms
41,396 KB
testcase_29 AC 119 ms
40,564 KB
testcase_30 AC 128 ms
41,368 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