We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5f1ab6b commit 49a3396Copy full SHA for 49a3396
Project Euler/Problem 05/sol2.py
@@ -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