Almost Perfect

Run Settings
LanguageGo
Language Version
Run Command
package main import ( "fmt" "math" ) //O(akar n) func checkPerfect(n int) string{ countDiv :=1 sq := int(math.Sqrt(float64(n))) for i:=2;i<=sq;i++{ // mencari yg bisa membagi if n%i == 0{ if i != n/i{ countDiv +=n/i } countDiv +=i } } if countDiv == n { return fmt.Sprintf("%d perfect", n) }else if (int(math.Abs(float64(countDiv)-float64(n))) <= 2){ return fmt.Sprintf("%d almost perfect",n) }else{ return fmt.Sprintf("%d not perfect",n) } } func main() { fmt.Println(checkPerfect(6)) }
Editor Settings
Theme
Key bindings
Full width
Lines