結果

問題 No.7 プライムナンバーゲーム
ユーザー tsuchinagatsuchinaga
提出日時 2019-05-10 11:57:08
言語 Go
(1.22.1)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 677 bytes
コンパイル時間 13,903 ms
コンパイル使用メモリ 233,672 KB
実行使用メモリ 6,696 KB
最終ジャッジ日時 2024-04-09 04:38:01
合計ジャッジ時間 15,051 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,564 KB
testcase_01 AC 1 ms
6,688 KB
testcase_02 AC 1 ms
6,692 KB
testcase_03 AC 2 ms
6,692 KB
testcase_04 AC 1 ms
6,688 KB
testcase_05 AC 1 ms
6,692 KB
testcase_06 AC 2 ms
6,688 KB
testcase_07 AC 2 ms
6,692 KB
testcase_08 AC 2 ms
6,688 KB
testcase_09 AC 2 ms
6,696 KB
testcase_10 AC 2 ms
6,692 KB
testcase_11 AC 2 ms
6,688 KB
testcase_12 AC 3 ms
6,688 KB
testcase_13 AC 2 ms
6,688 KB
testcase_14 AC 3 ms
6,692 KB
testcase_15 AC 3 ms
6,692 KB
testcase_16 AC 2 ms
6,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import "fmt"

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

	pn := make([]int, 0)
	pnn := make([]int, n+1)
	for i := 2; i <= n; i++ {
		if pnn[i] == 0 {
			pn = append(pn, i)

			for j := i + i; j <= n; j += i {
				pnn[j] = 1
			}
		}
	}
	// fmt.Println(pn)

	// trueが勝ち、それ以外が負け
	// 負ける数字を渡せる数字は勝てる数字
	win := make([]bool, n+1)
	for i := 2; i <= n; i++ {
		if win[i] == true {
			continue
		}

		for _, p := range pn {
			if i+p <= n {
				win[i+p] = true
			}
		}

		if win[n] == true {
			break
		}
	}

	// fmt.Println(win)

	if win[n] == true {
		fmt.Println("Win")
	} else {
		fmt.Println("Lose")
	}
}
0