Skip to content

Instantly share code, notes, and snippets.

@samuelhnrq
Created May 24, 2017 21:11
Show Gist options
  • Save samuelhnrq/c10b21c45b1e69e515c315608734e225 to your computer and use it in GitHub Desktop.
Save samuelhnrq/c10b21c45b1e69e515c315608734e225 to your computer and use it in GitHub Desktop.
func smallestMult() {
fmt.Println("searching for ans.")
res := 1
for i := 1; i <= 20; i++ {
j := maxPowPrime(i)
if j == 0 {
continue
}
res *= j
}
fmt.Println(res, "is the answer")
}
func maxPowPrime(x int) int {
//checks if prime in the first place
for y := 2; y < x; y++ {
if (x % y) == 0 {
return 0
}
}
pow := 2
p := int(math.Pow(float64(x), float64(pow)))
last := x
for p < 20 && x > 1 {
pow++
last = p
p = int(math.Pow(float64(x), float64(pow)))
}
return last
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment