結果

問題 No.25 有限小数
ユーザー warashiwarashi
提出日時 2015-11-06 15:13:25
言語 Go
(1.21.3)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 597 bytes
コンパイル時間 11,246 ms
コンパイル使用メモリ 215,936 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-01 03:47:55
合計ジャッジ時間 11,379 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,384 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
	}

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

	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