LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 3 years have passed since last update.

プログラミング問題集解答例(問15)

Last updated at Posted at 2019-12-04

問15

# ユークリッドの互除法で最大公約数を求める関数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)
def question15(p1, p2):
    return gcd(abs(p1[0] - p2[0]), abs(p1[1] - p2[1])) - 1
x1 =  -2
y1 =  -9
x2 =  6
y2 =  7
question15([x1, y1], [x2, y2])
7
x1 =  -42
y1 =  -65
x2 =  62
y2 =  -91
question15([x1, y1], [x2, y2])
25
x1 =  908
y1 =  -307
x2 =  -86
y2 =  -679
question15([x1, y1], [x2, y2])
1
x1 =  -6326
y1 =  3211
x2 =  7048
y2 =  5822
question15([x1, y1], [x2, y2])
0
x1 =  -9675
y1 =  -2803
x2 =  3828
y2 =  -6349
question15([x1, y1], [x2, y2])
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up