Help me in solving MXFACS problem

My issue

it say’s Time limit Exceeded
are there any changes to be made in the code

My code

#include <stdio.h>

int main(void) {
	// your code goes here
    int t;
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d",&n);
        int k,m,r,Kcount=0,Rcount=0;
        for(k=2;k<=n;k++){
            if((n%k)==0){
                for(int i=1;i<=(n/k);i++){
                    if((n/k)%i==0){
                        Kcount++;
                    }
                }
                if(Rcount<Kcount){
                    r=k;
                    Rcount=Kcount;
                }
            }
            Kcount=0;
        }
        printf("%d\n",r);
        //("\n");
    }
}


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