DEV Community

Cover image for Smallest multiple - Project Euler Solution
Deepak Raj
Deepak Raj

Posted on • Edited on • Originally published at codeperfectplus.com

5 5

Smallest multiple - Project Euler Solution

Smallest multiple - Project Euler Solution

Topic: Smallest multiple

Problem Statement:

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

You can find the original question here -> Project Euler

Smallest multiple - Project Euler Solution in python

from math import gcd
def lcm(a,b):
    "Calculate the lowest common multiple of two integers a and b"
    return a*b//gcd(a,b)

from functools import reduce

result = reduce(lcm, range(1,11))
print(result)
Enter fullscreen mode Exit fullscreen mode

Share Your Solutions for smallest multiple

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

Retry later