Skip to content

Commit 49a3396

Browse files
committed
Added a Solution using Euclidean Algo
1 parent 5f1ab6b commit 49a3396

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Project Euler/Problem 05/sol2.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/python3
2+
'''
3+
Problem:
4+
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
5+
What is the smallest positive number that is evenly divisible(divisible with no remainder) by all of the numbers from 1 to N?
6+
'''
7+
8+
""" Euclidean GCD Algorithm """
9+
def gcd(x,y):
10+
return x if y==0 else gcd(y,x%y)
11+
12+
""" Using the property lcm*gcd of two numbers = product of them """
13+
def lcm(x,y):
14+
return (x*y)//gcd(x,y)
15+
16+
n = int(input())
17+
g=1
18+
for i in range(1,n+1):
19+
g=lcm(g,i)
20+
print(g)

0 commit comments

Comments
 (0)