結果

問題 No.751 Frac #2
ユーザー tsuchinagatsuchinaga
提出日時 2019-03-15 00:12:42
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 765 bytes
コンパイル時間 12,592 ms
コンパイル使用メモリ 212,596 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-09 21:46:21
合計ジャッジ時間 14,992 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

import "fmt"

func main() {
	var n, a, m int

	var c, p []int // 分子, 分母

	for i := 0; i < 2; i++ {
		_, _ = fmt.Scan(&n)
		for j := 0; j < n; j++ {
			_, _ = fmt.Scan(&a)
			if a < 0 {
				a *= -1
				m++
			}

			if (i == 0 && j == 0) || (i == 1 && j != 0) {
				for k := range p {
					d := divisor751(a, p[k])
					a /= d
					p[k] /= d
				}

				c = append(c, a)
			} else {
				for k := range c {
					d := divisor751(a, c[k])
					a /= d
					c[k] /= d
				}

				p = append(p, a)
			}
		}
	}

	cn, pn := 1, 1
	for i := range c {
		cn *= c[i]
	}
	for i := range p {
		pn *= p[i]
	}
	if m%2 == 1 {
		cn *= -1
	}

	fmt.Printf("%d %d\n", cn, pn)
}

func divisor751(a, b int) int {
	if a%b == 0 {
		return b
	}
	return divisor751(b, a%b)
}
0