From 8a4eb8db171ea5af22067c4feab8df0b0031755b Mon Sep 17 00:00:00 2001 From: Rahul Arulkumaran Date: Thu, 14 Dec 2017 13:39:44 +0530 Subject: [PATCH 1/2] Add files via upload --- Competitive Coding/Math/Project_Euler/proj_euler_21.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Competitive Coding/Math/Project_Euler/proj_euler_21.py diff --git a/Competitive Coding/Math/Project_Euler/proj_euler_21.py b/Competitive Coding/Math/Project_Euler/proj_euler_21.py new file mode 100644 index 000000000..d5bd8db09 --- /dev/null +++ b/Competitive Coding/Math/Project_Euler/proj_euler_21.py @@ -0,0 +1,10 @@ +def divisors(n): #function to find divisors of a number + sum=1 #initialising sum as 1 as 1 is a multiple of all numbers + for i in range(2,n/2+1): #running loop from 2 to n/2+1 as the highest possible divisor of a number is half of the num + if(n%i==0): + sum+=i #calculating sum of divisors + print sum #prints sum of diviors + + +if __name__=='__main__': + divisors(10000) From 6eb31b2e5e9b79490d870c5f7d36510642835dc7 Mon Sep 17 00:00:00 2001 From: Rahul Arulkumaran Date: Thu, 14 Dec 2017 13:42:11 +0530 Subject: [PATCH 2/2] Update and rename proj_euler_21.py to sum_of_divisors.py --- .../Project_Euler/{proj_euler_21.py => sum_of_divisors.py} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename Competitive Coding/Math/Project_Euler/{proj_euler_21.py => sum_of_divisors.py} (59%) diff --git a/Competitive Coding/Math/Project_Euler/proj_euler_21.py b/Competitive Coding/Math/Project_Euler/sum_of_divisors.py similarity index 59% rename from Competitive Coding/Math/Project_Euler/proj_euler_21.py rename to Competitive Coding/Math/Project_Euler/sum_of_divisors.py index d5bd8db09..5dec46645 100644 --- a/Competitive Coding/Math/Project_Euler/proj_euler_21.py +++ b/Competitive Coding/Math/Project_Euler/sum_of_divisors.py @@ -1,9 +1,9 @@ def divisors(n): #function to find divisors of a number - sum=1 #initialising sum as 1 as 1 is a multiple of all numbers + sum_digits=1 #initialising sum as 1 as 1 is a multiple of all numbers for i in range(2,n/2+1): #running loop from 2 to n/2+1 as the highest possible divisor of a number is half of the num if(n%i==0): - sum+=i #calculating sum of divisors - print sum #prints sum of diviors + sum_digits+=i #calculating sum of divisors + print sum_digits #prints sum of diviors if __name__=='__main__':