number_theory0

798 days ago by jozefl

Let's look at a few common number theoretic functions.

lcm(515,2005) 
       
gcd(515,2005) 
       
factor(2005) 
       
next_prime(2005) 
       
previous_prime(2005) 
       

Let's look at the 'divisors' function. The argument is an integer, and the function returns a vector of the factors (which sets it apart from the 'factor' function, which returns the divisors as a product).

divs=divisors(28); print 'The divisors of 28 are: \n',divs sumdivs=sum(divisors(28)); print 'The sum of the divisors of 28 is ',sumdivs print '2*28 = ',2*28 
       

Hmmm. This gives me an idea:

n=28 if sum(divisors(n))-n==n: print n,' is a perfect number.' else: print n,' is not a perfect number.'