@anon27703279
yeah the answer would be 3 because in the prime factorization of n 3 comes more than 2 that’s y the answer would be 3
plzz refer my c++ code for better understanding of the logic
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
map<int,int> mp;
while(n%2==0)
{
n=n/2;
mp[2]++;
}
for(int i=3;i<=sqrt(n);i+=2)
{
if(n%i==0)
{
while(n%i==0)
{
n=n/i;
mp[i]++;
}
}
}
if(n>2)
mp[n]++;
int mx=0;
for(auto x:mp)
{
mx=max(mx,x.second);
}
for(auto x:mp)
{
if(x.second==mx)
{
cout<<x.first<<endl;
break;
}
}
}
}
The lowest divisor is not necessarily the answer. Consider N = 18. If you choose K = 2 then M = 9, which has three divisors. However if you choose K = 3, M = 6 which has 4 divisors and is the answer.
More generally, if prime factorization of N is: N = p_1^{a_1} \cdot p_2^{a_2} \cdot ... \cdot p_k^{a_k}, the number of divisors of N would be \phi(N) = (1+a_1)\cdot(1+a_2)\cdot ... (1+a_k).
If you choose a prime p_i to divide, the difference in number of divisors would be: \phi(N)-\phi({\frac{N}{p_i}}) = \frac{\phi(N)}{1+a_i}
To maximize \phi(\frac{N}{p_i}), we would want to minimize the difference. This would occur when we choose such a prime p_i that a_i is maximum.