結果

問題 No.25 有限小数
ユーザー warashiwarashi
提出日時 2015-11-06 19:54:42
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 657 bytes
コンパイル時間 10,667 ms
コンパイル使用メモリ 219,404 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-19 03:32:04
合計ジャッジ時間 17,694 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,912 KB
testcase_01 AC 1 ms
5,376 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 1 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 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
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 1 ms
5,376 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

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
	}

	// 末尾の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