Created
June 29, 2015 10:34
-
-
Save nawada/ececcfb8abc9480d456f 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
package main | |
import ( | |
"fmt" | |
"os" | |
"strconv" | |
) | |
func main() { | |
val1, err1 := strconv.Atoi(os.Args[1]) | |
val2, err2 := strconv.Atoi(os.Args[2]) | |
if err1 != nil || err2 != nil { | |
val1, val2 = 1, 1 | |
} | |
result1, _ := EuclideanMethod(val1, val2) | |
fmt.Println(result1) | |
} | |
func EuclideanMethod(val1 int, val2 int) (int, int) { | |
if val2 == 0 { | |
return val1, val2 | |
} else if val2 > val1 { | |
result := val2 % val1 | |
return EuclideanMethod(val1, result) | |
} else { | |
result := val1 % val2 | |
return EuclideanMethod(val2, result) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment