Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

SoHoanHao

package main

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

func TimUocSo(n int) []int {
  var res []int

  for i := 1; i <= n/2; i++ {
    if n%i == 0 {
      res = append(res, i)
    }
  }

  return res
}

func KTSoHoanHao(n int) bool {
  UocSo := TimUocSo(n)
  for _, v := range UocSo {
    n -= v
  }

  if n == 0 {
    return true
  }

  return false
}

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    Input := scanner.Text()
    ID, err := strconv.Atoi(Input)
    if err != nil {
        panic(err)
    }
  
  if KTSoHoanHao(ID) {
    fmt.Printf("%d la so hoan hao !\n", ID)
  } else {
    fmt.Printf("%d khong phai la so hoan hao\n", ID)
  }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.