forked from course-work/week1
Update 05-sum_of_divisors/wtf.py
This commit is contained in:
parent
7c7857a462
commit
9a4c854521
@ -1,14 +1,40 @@
|
|||||||
|
import fractions
|
||||||
|
|
||||||
def compute_divisors(num):
|
def compute_divisors(num):
|
||||||
pass
|
divisors = [1]
|
||||||
|
for i in range( 2, num//2+1 ): # if num is even, one needs to be added
|
||||||
|
if num % i == 0:
|
||||||
|
divisors.append(i)
|
||||||
|
|
||||||
|
divisors.append( num )
|
||||||
|
|
||||||
|
return divisors
|
||||||
|
|
||||||
def sum_of_divisors(num):
|
def sum_of_divisors(num):
|
||||||
pass
|
sumOf = 0
|
||||||
|
for i in compute_divisors( num ):
|
||||||
|
sumOf += i
|
||||||
|
|
||||||
|
return sumOf
|
||||||
|
|
||||||
def divisor_count(num):
|
def divisor_count(num):
|
||||||
pass
|
return len( compute_divisors(num) )
|
||||||
|
|
||||||
def get_totatives(num):
|
def get_totatives(num):
|
||||||
pass
|
totatives = []
|
||||||
|
for i in range(0, num):
|
||||||
|
gcd = fractions.gcd( i, num )
|
||||||
|
if gcd == 1:
|
||||||
|
totatives.append( i )
|
||||||
|
|
||||||
|
return totatives
|
||||||
|
|
||||||
def totient(num):
|
def totient(num):
|
||||||
pass
|
return len( get_totatives(num) )
|
||||||
|
|
||||||
|
|
||||||
|
assert( compute_divisors(60) == [1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60] )
|
||||||
|
assert( sum_of_divisors(60) == 168 )
|
||||||
|
assert( divisor_count(60) == 12 )
|
||||||
|
assert( get_totatives(30) == [1, 7, 11, 13, 17, 19, 23, 29] )
|
||||||
|
assert( totient(30) == 8 )
|
Loading…
x
Reference in New Issue
Block a user