The challenge

Solution

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	text, _ := reader.ReadString('\n')
	text = strings.TrimSuffix(text, "\n")

	if len(text) == 0 {
		return
	}
	l, err := strconv.Atoi(text)
	if err != nil {
		fmt.Println(err)
	}

	i := 0
	for {
		text, _ := reader.ReadString('\n')
		text = strings.TrimSuffix(text, "\n")

		if len(text) == 0 {
			break
		}
		n, err := strconv.Atoi(text)
		if err != nil {
			fmt.Println(err)
		}
		calc(n)
		i = i + 1
		if i >= l {
			break
		}
	}

}

func calc(n int) {
	orig := n
	digits := 0
	if n <= 0 {
		return
	}
	if n > int(math.Pow(10.0, float64(9))) {
		return
	}

	i := 1
	for {
		if i > n {
			break
		}
		i = i * 10
		digits = digits + 1

	}

	values := []int{}

	for i := digits - 1; i >= 0; i-- {
		d := int(math.Pow(10.0, float64(i)))
		val := int(n / d)
		n = n - val*d
		values = append(values, val)
	}

	res := 0

	for _, i := range values {
		if i != 0 && orig%i == 0 {
			res++
		}
	}

	fmt.Println(res)

}