Help us understand the problem. What is going on with this article?

#ユークリッドの互除法を標準モジュールを用いずに実装する。for Python

More than 1 year has passed since last update.

目的

自然界に存在する数式を実装する練習として行いました。

思考過程

1.このアルゴリズムでは、任意の2つの数字(a,b a>bとする)について、大きい数字を小さい数字で割った余りで前の演算時の小さい数字を割っていく。

2.余りが0になった時のbが最大公約数である。

code

GCD.py
def GCD(a,b):
    if a<b:
        yu_kurid(b,a)

    while a % b !=0 :
        n = a % b
        a = b
        b = n
    return b
if __name__ == __main__:
     GCD(680,90)

実行結果

10

最後に

簡単なアルゴリズムなので次はもっと難しいものを実装したいですね。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away