Looking for the lowest number divisible by 1 to A.

368 Views Asked by At

What would the math equation be for finding the lowest number divisible by 1 to A? I know factorial can make numbers divisible by 1 to A but that dosn't give me the lowest number.

Example of what I'm talking about:

the lowest number divisible by 1,2,3,4,5,6,7,8 = 840

Example of factorial (What I'm not talking about):

8! = 40,320

Note:

A is anything that's more then 1 and is whole.

3

There are 3 best solutions below

1
On BEST ANSWER

You can write it as $LCM(1,2,3,4,\dots A)$ To figure it out, you take the highest power of each prime less than $A$ and multiply them. For $A=37$, we have $2^5,3^3,5^2$ and all other primes less than $37$, so it is $2^5\cdot 3^3\cdot 5^2\cdot 7 \cdot 11 \dots \cdot 37$ They are given in OEIS A003418

2
On

Look at the LCM. Note $lcm\{a,b\} = \frac{ab}{gcd(a, b)}$.

If you have a prime $p$ and a power of $p$, $p^{n}$, you will simply discard $p$ and keep $p^{n}$ instead. As $p^{n}|x \implies p|x$, but the converse is not true.

Note as well you can ignore $1$ in your $gcd$ calculations.

4
On

The problem with taking the factorial is that it repeats prime powers too many times: For example, $8!$ contains $6$ powers of $2$, while $8$ is only divisble by $2^3$.

You're looking for the number that's divisible by all the primes at most $A$, and powers of primes that are still less than $A$; to this end, let $P_A = \{p_1, p_2,\dots p_n\}$ be the collection of primes in $\{1, \dots, A\}$. Then for primes $p$,

$$p^k \le A \iff k \le \frac{\log A}{\log p}$$

Thus, the desired number is

$$\operatorname{lcm}(1,2,\dots,A) = \prod_{k = 1}^n p_k^{\lfloor\log A / \log p_k\rfloor}$$ where $\lfloor \cdot \rfloor$ denotes the floor function.

As an example, for $A = 8$, we have $P_A = \{2,3,5,7\}$. Then the exponent for $2$ is $$\left\lfloor \frac{\log 8}{\log 2} \right\rfloor = 3$$ as expected. Similarly, the exponent for $3$ is $\lfloor \log 8 / \log 3\rfloor = 1$, and likewise for $5$ and $7$. Thus the desired number is

$$2^3 \cdot 3 \cdot 5 \cdot 7 = 840$$