Created
May 24, 2017 21:11
-
-
Save samuelhnrq/c10b21c45b1e69e515c315608734e225 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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