fix isprime
This commit is contained in:
parent
d76f21d508
commit
d07d4f0dd1
@ -5,6 +5,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"math"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func handler(w http.ResponseWriter, r *http.Request) {
|
func handler(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -13,16 +15,16 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Failed to parse %s as int! %v", target, err)
|
return "", fmt.Errorf("Failed to parse %s as int! %v", target, err)
|
||||||
}
|
}
|
||||||
logrus.Infof("Checking if %s is prime", target)
|
log.Print("Checking if %s is prime", target)
|
||||||
if num <= 1 {
|
if num <= 1 {
|
||||||
return fmt.Fprintf(w,"%d is not prime", num), nil
|
return fmt.Sprintf("%d is not prime", num), nil
|
||||||
}
|
}
|
||||||
for i := 2; i <= int(math.Floor(float64(num)/2)); i++ {
|
for i := 2; i <= int(math.Floor(float64(num)/2)); i++ {
|
||||||
if num%i == 0 {
|
if num%i == 0 {
|
||||||
return fmt.Fprintf(w,"%d is not prime", num), nil
|
return fmt.Sprintf("%d is not prime", num), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fmt.Fprintf(w,"%d is prime", num), nil
|
return fmt.Sprintf("%d is prime", num), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
Loading…
Reference in New Issue
Block a user