学習環境
- Surface 3 (4G LTE)、Surface 3 タイプ カバー、Surface ペン(端末)
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad Pro + Apple Pencil
- MyScript Nebo(iPad アプリ)
- 参考書籍
数学読本〈1〉数・式の計算/方程式/不等式 (松坂 和夫(著)、岩波書店)の第1章(数学はここから始まる-数)、1.3(整数)、素因数分解の問10.を取り組んでみる。
最大公約数。
最小公倍数。
最大公約数。
最小公倍数。
コード(Emacs)
Python 3
#!/usr/bin/env python3 from sympy import pprint, gcd, lcm print('10.') t = [ ( (3 ** 6 * 19 ** 2, 3 ** 3 * 7 ** 2 * 19), 3 ** 3 * 19, 3 ** 6 * 7 ** 2 * 19 ** 2 ), ( ( 2 ** 2 * 5 ** 2 * 13 ** 2, 2 ** 3 * 5 * 11 * 13, 2 ** 4 * 11 ** 2 * 13 ** 3 ), 2 ** 2 * 13, 2 ** 4 * 5 ** 2 * 11 ** 2 * 13 ** 3 ) ] for i, (nums, a, b) in enumerate(t, 1): print(f'({i})') g = nums[0] l = nums[0] for n in nums[1:]: g = gcd(g, n) l = lcm(l, n) print(g == a) print(l == b)
入出力結果(Terminal, Jupyter(IPython))
$ ./sample12.py 10. (1) True True (2) True True $
0 コメント:
コメントを投稿