diff --git a/021 - Amicable numbers/HackerRank_Project_Euler_021_001.py b/021 - Amicable numbers/HackerRank_Project_Euler_021_001.py index 057e343..cd4fd80 100644 --- a/021 - Amicable numbers/HackerRank_Project_Euler_021_001.py +++ b/021 - Amicable numbers/HackerRank_Project_Euler_021_001.py @@ -6,11 +6,11 @@ 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 @@ -18,21 +18,21 @@ def Sum_Of_Divisors(Number, Primes): 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): @@ -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 \ No newline at end of file + print(Sum) # Add an argument to print the result