1
$\begingroup$

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.

$\endgroup$
2
  • 3
    $\begingroup$ Can you answer the question when $m$ is prime? What if you knew the prime factorization of $m$? $\endgroup$ Commented Sep 1, 2023 at 18:21
  • $\begingroup$ If m is a prime, then n should be 'm' itself. And I have thought about the prime factorization of m, made a code based on that. I think that's the only way to calc n, but I want to know there's any way to make n the smallest. $\endgroup$ Commented Sep 1, 2023 at 18:27

1 Answer 1

2
$\begingroup$

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\,.$

$\endgroup$
1
  • $\begingroup$ You should prove your claaims. $\endgroup$ Commented Sep 1, 2023 at 20:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .