Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # This is an example python file for FCM C&C #56, which contains code to calculate abundant numbers within the range [2,500).
- # Pseudocode (Abundant numbers in Python)
- import math
- # Function based off the fact that any factors of a number are based around the square root. For each number (i) between 2 and sqrt(n) if the number is a factor, then n/i is the other factor. Complexity: O(sqrt(n))
- def sumfacs(n):
- t=1
- s=int(n**0.5)
- i=2
- while i<=s:
- if n%i==0:
- if n!= i*i: t+=n/i
- t+=i
- i+=1
- return int(t)
- abundant=[]
- # Since 12 is the smallest abundant number (factors of 12 = 1,2,3,4,6, sum of factors = 16, 16>12)
- for i in range(12, 500):
- if sumfacs(i) > i:
- abundant.append(i)
- print("All abundant numbers between 12 and 499: ",abundant)
- print("Total number found: ",len(abundant))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement