結果

問題 No.25 有限小数
ユーザー warashiwarashi
提出日時 2015-11-06 19:53:26
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 683 bytes
コンパイル時間 13,736 ms
コンパイル使用メモリ 239,796 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 03:31:45
合計ジャッジ時間 12,707 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
5,376 KB
testcase_16 WA -
testcase_17 AC 1 ms
5,376 KB
testcase_18 WA -
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
)

func main() {
	var N, M uint64
	fmt.Scan(&N, &M)
	g := gcd(N, M)
	N /= g
	M /= g

	// 末尾の0を取り除く
	// ここでやっておかないとオーバーフローする
	for N%10 == 0 {
		N /= 10
	}

	// 関係あるのは1の位だけ
	N %= 10

	// 分母分子を[2,5]で割って、小数になってしまうので10かける
	for M%2 == 0 {
		M /= 2
		N *= 5
	}
	for M%5 == 0 {
		M /= 5
		N *= 2
	}
	if M != 1 {
		fmt.Println(-1)
		return
	}

	// 末尾の0を取り除く
	for N%10 == 0 {
		N /= 10
	}
	fmt.Println(N % 10)
}
func gcd(a, b uint64) uint64 {
	if b < a {
		a, b = b, a
	}
	if b%a == 0 {
		return a
	}
	return gcd(b%a, a)
}
0