How to get the smallest $n$ that $n^n$ is divisible by $m$.

157 Views Asked by At

I have to calculate an integer $n$ when an integer $m$ is given, that $n^n$ is divisible by $m$. And the thing is, $n$ is the smallest number that satisfies this condition. Please help me how can I solve this using mathematics.

This is the python code that I have tried.

import math

def f(m: int) -> int:
    t = math.isqrt(m) + 1
    primes = [1 for i in range(0, t)]

    maxCount = 0
    factors = []
    p = 2

    result = 1

    while p < t and p < m:
        if primes[p] == 1 and m % p == 0:
            for i in range(p + p, t):
                primes[i] = 0

            c = 0
            while m % p == 0:
                m = m // p
                c += 1
            if maxCount < c:
                maxCount = c
            result *= p
            factors.append(p)
        p += 1
    factors.append(p)
    if m > 1:
        result *= m
    if maxCount <= result:
        return result
    p1 = math.ceil(maxCount / result)
    for p in primes:
        if p >= p1:
            return result * p
    return result

In the code, I get all the primes that made $m$. And my work was to get every $p$, for every prime to $\mathrm{prime}^p$. With my code, I get the $n$ that is $n^n$ is divisible by $m$, but in some cases it was not the smallest.

1

There are 1 best solutions below

1
On

Let $\,m=p_1^{r_1}p_2^{r_2}\ldots p_t^{r_t}$ be the factorization of the positive integer $\,m\geqslant2\,.$

We can obtain the smallest positive integer $\,n\,$ such that $\,n^n$ is divisible by $\,m\,$ in the following way.

Let $\,r=\max\{r_1,r_2,\ldots,r_t\}\,.$

Let $\,k\,$ the smallest positive integer number such that

$k\geqslant\dfrac r{p_1p_2\ldots p_t}\;\;,\;\;$ that is , $\;\;k=\left\lceil\dfrac r{p_1p_2\ldots p_t}\right\rceil.$

The smallest positive integer $\,n\,$ such that $\,n^n$ is divisible by $\,m\,$ is $\;n=kp_1p_2\ldots p_t\,.$