結果

問題 No.6 使いものにならないハッシュ
ユーザー fmhrfmhr
提出日時 2016-07-31 09:50:48
言語 Go
(1.22.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,172 bytes
コンパイル時間 10,996 ms
コンパイル使用メモリ 209,500 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-14 23:00:21
合計ジャッジ時間 12,420 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

import (
	"fmt"
	"sort"
)

func main() {
	var K, N int
	fmt.Scan(&K, &N)
	pl := Sieve(N)
	sort.Ints(pl)
	i := 0
	for pl[i] < K {
		i++
	}
	pl = pl[i:]
	hashList := make([]int, len(pl))
	for i, m := range pl {
		hashList[i] = hash(m)
	}
	ans := 0
	ans_len := 0
	for i := 0; i < len(hashList); i++ {
		for j := i + 1; j < len(hashList); j++ {
			flag := true
			for _, v := range hashList[i:j] {
				if v == hashList[j] {
					flag = false
				}
			}
			if flag {
				if j-i+1 > ans_len {
					ans = pl[i]
					ans_len = j - i + 1
				} else if j-i+1 == ans_len {
					ans = max(ans, pl[i])
				}
			} else {
				break
			}
		}
	}
	fmt.Println(ans)
}

func hash(m int) int {
	for m >= 10 {
		n := m
		m = 0
		for n > 0 {
			m += n % 10
			n /= 10
		}
	}
	return m
}

func Sieve(n int) []int {
	isNotPrime := make([]bool, n+1)
	primeList := make([]int, 0)
	isNotPrime[0] = true
	isNotPrime[1] = true
	for i := 2; i <= n; i++ {
		if !isNotPrime[i] { // 素数の場合
			primeList = append(primeList, i)
			for j := 2 * i; j <= n; j += i {
				isNotPrime[j] = true
			}
		}
	}
	return primeList
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
0