Size: 2236
Comment:
|
Size: 2420
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 12: | Line 12: |
* この例題のポイント: mathモジュールのgcd()関数 | * この例題のポイント: [[https://docs.python.jp/3/library/math.html|mathモジュール]]の[[https://docs.python.jp/3/library/math.html#math.gcd|gcd()]]関数 |
Line 14: | Line 14: |
||<|3>例題(9)||<|3> 【組込関数】||<|1>[[https://ja.wikipedia.org/wiki/最大公約数|最大公約数]] gcd ( greatest common divisor )|| ||<|1> mathモジュールのgcd()関数を利用する|| |
||<|3>例題(9)||<|3> 【組込関数】||<|1>[[https://ja.wikipedia.org/wiki/最大公約数|最大公約数]] gcd (greatest common divisor)|| ||<|1> [[https://docs.python.jp/3/library/math.html|mathモジュール]]の[[https://docs.python.jp/3/library/math.html#math.gcd|gcd()]]関数を利用する|| |
例題(9)
例題(9)
【組込関数】
最大公約数 gcd (greatest common divisor)
- プログラムの本質的な部分は,下記の 行です.
- 例題ファイルとしては,コメントを付け加えた,下記を配布します.
- コメントはもう少し増えるかもしれません.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # ==============================================================================
4 # * Copyright (c) 2018 IIJIMA, Tadashi
5 # * (IIJIMA Laboratory, Dept. of Science and Technology, Keio University).
6 # ==============================================================================
7 # ソフトウェア工学[02] 例題[02]-(009a) Ex_02_009a_greatest_common_divisor_builtin.py
8 # Ex(Example) 02-009a: 【組込関数】 最大公約数 gcd ( greatest common divisor )の使い方.
9 # Python 3.3から導入された.
10 # 2018-10-03 飯島 正 (iijima@ae.keio.ac.jp)
11 # ==============================================================================
12 # ----- 数学関数を扱うためのmathモジュールをインポートする -----
13 import math
14 # ==============================================================================
15 # ===== 【メイン・プログラム】 =====
16 print( math.gcd( 350, 450 ) )
17 # ==============================================================================