# Help me in solving MXFACS problem

### My issue

my output is correct why in your test case showing differently check out

### My code

``````import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();

while(t-->0)
{
int no=sc.nextInt();

for(int i=2;i<=no;i++)
{
if(no%i==0){
System.out.println(i);
break;
}
}
}

}
}

``````

Learning course: 2000 to 2500 difficulty problems
Problem Link: Maximum Factors Problem Practice Problem in 2000 to 2500 difficulty problems

@abdulrehamanit
here plzz refer my c++ code for better understanding of the logic

``````#include <bits/stdc++.h>
using namespace std;

int main() {
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;
}
}
}
}``````