結果

問題 No.816 Beautiful tuples
ユーザー tsuchinagatsuchinaga
提出日時 2019-04-20 23:45:58
言語 Go
(1.21.3)
結果
AC  
実行時間 249 ms / 1,500 ms
コード長 747 bytes
コンパイル時間 13,319 ms
コンパイル使用メモリ 203,020 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-25 16:29:46
合計ジャッジ時間 15,300 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 161 ms
4,380 KB
testcase_05 AC 37 ms
4,380 KB
testcase_06 AC 112 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 13 ms
4,376 KB
testcase_09 AC 81 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 249 ms
4,380 KB
testcase_12 AC 12 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import "fmt"

func main() {
	var a, b int
	_, _ = fmt.Scan(&a, &b)

	check := func(c int) bool {
		return a != c && b != c && (a+b)%c == 0 && (b+c)%a == 0 && (c+a)%b == 0
	}

	if check(1) {
		fmt.Println(1)
		return
	}

	// 素因数分解
	n := a + b
	pn := make([]int, 0)
	for i := 2; i < n+1; i++ {
		if n%i == 0 {
			is := true
			for _, p := range pn {
				if i%p == 0 {
					is = false
					break
				}
			}
			if is {
				for n%i == 0 {
					n /= i
					// fmt.Println(i, n)
					pn = append(pn, i)
				}
			}
		}
	}
	// fmt.Println(pn)

	pattern := map[int]int{1: 1}
	for _, p := range pn {
		for q := range pattern {
			if check(p * q) {
				fmt.Println(p * q)
				return
			}
			pattern[p*q] = 1
		}
	}

	fmt.Println(-1)
}
0