結果

問題 No.6 使いものにならないハッシュ
ユーザー fmhrfmhr
提出日時 2016-07-31 09:43:19
言語 Go
(1.22.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,344 bytes
コンパイル時間 10,058 ms
コンパイル使用メモリ 199,764 KB
実行使用メモリ 5,612 KB
最終ジャッジ日時 2023-10-14 23:01:11
合計ジャッジ時間 11,246 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 3 ms
5,612 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,356 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,352 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,356 KB
testcase_14 AC 3 ms
4,352 KB
testcase_15 AC 2 ms
4,356 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 3 ms
4,352 KB
testcase_18 AC 3 ms
5,612 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 1 ms
4,352 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 3 ms
4,352 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 2 ms
4,352 KB
testcase_26 AC 3 ms
4,352 KB
testcase_27 AC 3 ms
4,352 KB
testcase_28 AC 2 ms
4,372 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,352 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, 0)
	for _, m := range pl {
		if m >= K {
			y := HashNum(m)
			hashList = append(hashList, y)
		}
	}
	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 HashNum(m int) int {
	for m >= 10 {
		y := 0
		n := m
		for n > 0 {
			y += n % 10
			n /= 10
		}
		m = y
	}
	return m
}

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

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