Data update
This commit is contained in:
parent
61b93a2cd1
commit
5af6d93694
858 changed files with 20572 additions and 2082 deletions
30
Task/Duffinian-numbers/Python/duffinian-numbers.py
Normal file
30
Task/Duffinian-numbers/Python/duffinian-numbers.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# duffinian.py by xing216
|
||||
|
||||
def factors(n):
|
||||
factors = []
|
||||
for i in range(1, n + 1):
|
||||
if n % i == 0:
|
||||
factors.append(i)
|
||||
return factors
|
||||
def gcd(a, b):
|
||||
while b != 0:
|
||||
a, b = b, a % b
|
||||
return a
|
||||
is_relively_prime = lambda a, b: gcd(a, b) == 1
|
||||
sigma_sum = lambda x: sum(factors(x))
|
||||
is_duffinian = lambda x: is_relively_prime(x, sigma_sum(x)) and len(factors(x)) > 2
|
||||
count = 0
|
||||
i = 0
|
||||
while count < 50:
|
||||
if is_duffinian(i):
|
||||
print(i, end=' ')
|
||||
count += 1
|
||||
i+=1
|
||||
count2 = 0
|
||||
j = 0
|
||||
while count2 < 20:
|
||||
if is_duffinian(j) and is_duffinian(j+1) and is_duffinian(j+2):
|
||||
print(f"({j},{j+1},{j+2})", end=' ')
|
||||
count2 += 1
|
||||
j+=3
|
||||
j+=1
|
||||
Loading…
Add table
Add a link
Reference in a new issue