package main import ( "fmt" "sort" ) func main() { var K, N int fmt.Scan(&K, &N) pl := Sieve(K, N) sort.Ints(pl) 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++ { numMap := make(map[int]int) numMap[hashList[i]] = 1 for j := i + 1; j < len(hashList); j++ { numMap[hashList[j-1]] = 1 _, flag := numMap[hashList[j]] //fmt.Println(len(numMap)) 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(k, 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] { // 素数の場合 if i >= k { 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 }