- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Smallest possible number divisible by all numbers from 1 to n in JavaScript

## Problem

We are required to write a JavaScript function that takes in a number n. Our function should find and return that smallest possible number which is divisible by all numbers from 1 to n.

## Example

Following is the code −

const num = 11; const smallestDivisible = (num = 1) => { let res = num * (num - 1) || 1; for (let i = num - 1; i >= 1; i--) { if (res % i) { for (let j = num - 1; j >= 1; j--) { if (!(i % j) && !(res % j)) { res = i * res / j; break; } } } } return res; } console.log(smallestDivisible(num));

## Output

27720

- Related Articles
- Smallest number that is divisible by first n numbers in JavaScript
- Count pairs of numbers from 1 to N with Product divisible by their Sum in C++
- Count n digit numbers divisible by given number in C++
- Find kth smallest number in range [1, n] when all the odd numbers are deleted in C++
- Largest N digit number divisible by given three numbers in C++
- Greatest number divisible by n within a bound in JavaScript
- Count numbers which are divisible by all the numbers from 2 to 10 in C++
- Possible to make a divisible by 3 number using all digits in an array in C++
- Python Program to Print all Numbers in a Range Divisible by a Given Number
- Golang Program to Print all Numbers in a Range Divisible by a Given Number
- Compute sum of digits in all numbers from 1 to n
- Generating a random number that is divisible by n in JavaScript
- Program to find all missing numbers from 1 to N in Python
- How to Display all Prime Numbers from 1 to N in Golang?
- Find the least number that is divisible by all the numbers between 1 and 10 (both inclusive).

Advertisements