最大公約数(ユークリッドの互除法)
gcd = lambda m, n: n and gcd(n, m % n) or m
オイラーのφ関数
eulerphi = lambda n: sum(int(gcd(m + 1, n) == 1) for m in range(n))
テスト
>>> [eulerphi(n+1) for n in range(16)]
[1, 1, 2, 2, 4, 2, 6, 4, 6, 4, 10, 4, 12, 6, 8, 8]
Go to list of users who liked
More than 1 year has passed since last update.
gcd = lambda m, n: n and gcd(n, m % n) or m
eulerphi = lambda n: sum(int(gcd(m + 1, n) == 1) for m in range(n))
>>> [eulerphi(n+1) for n in range(16)]
[1, 1, 2, 2, 4, 2, 6, 4, 6, 4, 10, 4, 12, 6, 8, 8]
Register as a new user and use Qiita more conveniently
Go to list of users who liked