package main import ( "bufio" "fmt" "io" "os" "strconv" "strings" ) func main() { sc := NewScanner(os.Stdin) A, _ := sc.NextInt() B, _ := sc.NextInt() for i := A; i <= B; i++ { if i%3 == 0 { fmt.Println(i) } else if includedThree(i) { fmt.Println(i) } } } // BenchmarkIncludedThree 20000000 119 ns/op 0 B/op 0 allocs/op // BenchmarkIncludedThreeByStringsContains 5000000 245 ns/op 15 B/op 1 allocs/op func includedThree(n int) bool { for n > 0 { if n%10 == 3 { return true } n /= 10 } return false } func includedThreeByStringsContains(n int) bool { return strings.Contains(strconv.Itoa(n), "3") } type scanner struct { *bufio.Scanner } func NewScanner(r io.Reader) *scanner { return &scanner{ bufio.NewScanner(r), } } func (s *scanner) Next() (string, error) { s.Scanner.Split(bufio.ScanWords) return s.nextToken() } func (s *scanner) nextToken() (string, error) { sc := s.Scanner if sc.Scan() { return sc.Text(), nil } if sc.Err() != nil { return "", sc.Err() } return "", io.EOF } func (s *scanner) NextInt() (int, error) { token, err := s.Next() if err != nil { return 0, err } return strconv.Atoi(token) }