From c787a22d932f8506792bb46057930aaa4e73f2f8 Mon Sep 17 00:00:00 2001 From: Thejus-Paul Date: Mon, 20 Nov 2017 01:34:21 +0530 Subject: [PATCH 1/2] Problem 16 Added Solution to the Problem 16 has been added. --- Project Euler/Problem 16/sol1.py | 15 +++++++++++++++ Project Euler/README.md | 3 +++ 2 files changed, 18 insertions(+) create mode 100644 Project Euler/Problem 16/sol1.py diff --git a/Project Euler/Problem 16/sol1.py b/Project Euler/Problem 16/sol1.py new file mode 100644 index 000000000..05c7916bd --- /dev/null +++ b/Project Euler/Problem 16/sol1.py @@ -0,0 +1,15 @@ +power = int(input("Enter the power of 2: ")) +num = 2**power + +string_num = str(num) + +list_num = list(string_num) + +sum_of_num = 0 + +print("2 ^",power,"=",num) + +for i in list_num: + sum_of_num += int(i) + +print("Sum of the digits are:",sum_of_num) diff --git a/Project Euler/README.md b/Project Euler/README.md index 5d7238e40..c9dc2b468 100644 --- a/Project Euler/README.md +++ b/Project Euler/README.md @@ -49,3 +49,6 @@ PROBLEMS: Using the rule above and starting with 13, we generate the following sequence: 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1 Which starting number, under one million, produces the longest chain? + +16. 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. + What is the sum of the digits of the number 2^1000? From 033744155c5f26fda1fd09746b4ccc019980a232 Mon Sep 17 00:00:00 2001 From: Thejus-Paul Date: Mon, 27 Nov 2017 10:44:32 +0530 Subject: [PATCH 2/2] Added Solution Added Solution for Problem 20 --- Project Euler/Problem 20/sol1.py | 27 +++++++++++++++++++++++++++ Project Euler/README.md | 4 ++++ 2 files changed, 31 insertions(+) create mode 100644 Project Euler/Problem 20/sol1.py diff --git a/Project Euler/Problem 20/sol1.py b/Project Euler/Problem 20/sol1.py new file mode 100644 index 000000000..73e41d5cc --- /dev/null +++ b/Project Euler/Problem 20/sol1.py @@ -0,0 +1,27 @@ +# Finding the factorial. +def factorial(n): + fact = 1 + for i in range(1,n+1): + fact *= i + return fact + +# Spliting the digits and adding it. +def split_and_add(number): + sum_of_digits = 0 + while(number>0): + last_digit = number % 10 + sum_of_digits += last_digit + number = int(number/10) # Removing the last_digit from the given number. + return sum_of_digits + +# Taking the user input. +number = int(input("Enter the Number: ")) + +# Assigning the factorial from the factorial function. +factorial = factorial(number) + +# Spliting and adding the factorial into answer. +answer = split_and_add(factorial) + +# Printing the answer. +print(answer) diff --git a/Project Euler/README.md b/Project Euler/README.md index c9dc2b468..9f77f719f 100644 --- a/Project Euler/README.md +++ b/Project Euler/README.md @@ -52,3 +52,7 @@ PROBLEMS: 16. 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2^1000? +20. n! means n × (n − 1) × ... × 3 × 2 × 1 + For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, + and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27. + Find the sum of the digits in the number 100!