MXMLCM using maps

Hi, the code is using maps to store the power of each factor of each number in the array,
then it stores the product of all the powers of the factors which are greater than the maximum power of that factor in the array;
example:
array : 81 4
map stores:
2 2
3 4

but this is not working, can someone help debug the code?

#include<iostream>
#include<map>
using namespace std;
int main()
{
    int test;
    cin>>test;
    while(test--)
    {
        int n,m;
        cin>>n>>m;
        int temp;
        map<int,int> mp;
        for(int i=0;i<n;i++) 
        {
            cin>>temp;
            map<int,int> mp3;
            
            for(int j=2;j*j<=temp;j++)
            {
                while(temp%j==0)
                {
                    temp/=j;
                    mp3[j]++;
                }
                if(mp[j]<mp3[j]) mp[j]=mp3[j];
            }
        }
        int ans=0;
        int pos=1;
        for(int i=1;i<=m;i++)
        {
            int temp=1;
            map<int,int> mp3;
            
            for(int j=2;j*j<=i;j++)
            {
                while(i%j==0)
                {
                    i/=j;
                    mp3[j]++;
                }
                cout<<j<<" "<<mp3[j]<<endl;
                if(mp[j]<mp3[j]) temp*=(mp3[j]-mp[j]);
            }
            if(ans<temp) {ans=temp; pos=i;}
        }
        cout<<pos<<endl;
    }
}