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

アルゴリズム自習

なんでアルゴリズム

日課としてるpaizaのスキルチェックでBランクで時間内にとけない問題が散見してきたので、アルゴリズムの学び直しを日課に追加したので復習用をかねての備忘録

この歳まで見てみないふりしてきた貧弱なアルゴリズム基礎体力をこれを機に人並みくらいにはあげたい。

日課

  1. Udemyでデータ解析のお勉強
  2. UdemyでReactのお勉強
  3. freeCodeCampでJavaScriptのお勉強
  4. paizaでスキルチェック
  5. AIZU ONLINE JUDGEのコースでアルゴリズムのお勉強(new!)

最大公約数(Greatest Common Divisor)

最大公約数を求めるアルゴリズムですね。
ユークリッド互除法の実装。
計算量は、O(logN)

def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x%y)

if __name__=='__main__':
    # 標準入力から最大公約数を算出する2値を取得する
    x, y = map(int, input().split())
    if y > x:
        x, y = y, x

    result = gcd(x, y)
    # 結果を出力
    print(result)
Why not register and get more from Qiita?
  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
No 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
ユーザーは見つかりませんでした