Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update HackerRank_Project_Euler_021_001.py #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions 021 - Amicable numbers/HackerRank_Project_Euler_021_001.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ def Sum_Of_Divisors(Number, Primes):
while i < len(Primes) and Primes[i] ** 2 <= Factor and Factor > 1:
if Factor % Primes[i] == 0:
Temp = Primes[i] ** 2
Factor = Factor / Primes[i]
Factor = Factor // Primes[i] # Integer division in Python 3
while Factor % Primes[i] == 0:
Temp *= Primes[i]
Factor = Factor / Primes[i]
Sum *= (Temp - 1) / (Primes[i] - 1)
Factor = Factor // Primes[i] # Integer division in Python 3
Sum *= (Temp - 1) // (Primes[i] - 1) # Integer division in Python 3
i += 1
if Factor > 1:
Sum *= Factor + 1
return Sum - Number

A = []
Primes = []
for j in xrange(0, int(10 ** 2.5)):
for j in range(0, int(10 ** 2.5)): # Range function in Python 3 doesn't include the stop value
A.append(True)
for j in xrange(2, int(10 ** 1.25)):
for j in range(2, int(10 ** 1.25)): # Range function in Python 3 doesn't include the stop value
if A[j] == True:
Primes.append(j)
for k in xrange(j * j, int(10 ** 2.5), j):
for k in range(j * j, int(10 ** 2.5), j): # Range function in Python 3 doesn't include the stop value
A[k] = False
for j in xrange(int(10 ** 1.25), int(10 ** 2.5)):
for j in range(int(10 ** 1.25), int(10 ** 2.5)): # Range function in Python 3 doesn't include the stop value
if A[j] == True:
Primes.append(j)
T = int(raw_input())
T = int(input()) # Use input() instead of raw_input() in Python 3
Largest = 0
Amicable = []
for i in range(T):
N = int(raw_input())
N = int(input()) # Use input() instead of raw_input() in Python 3
Sum = 0
if Largest < N:
for j in range(2, N):
Expand All @@ -52,4 +52,4 @@ def Sum_Of_Divisors(Number, Primes):
for j in range(len(Amicable)):
if Amicable[j] < N:
Sum += Amicable[j]
print Sum
print(Sum) # Add an argument to print the result