How to optimize this c program to find th eprime factorisation of a number : I have written a code for prime factorization of a number but i dont know how to optimize it to get better result for larger digits can anyone have idea about that?

    #include<stdio.h>
    int prime(int p, int q, int r);
    int main(){
	int n,c=0;
	scanf("%d",&n);
	for(int j=2;j<=n;j++){
		int t=0;
		for(int i=1;i<=j;i++){
			if(j%i==0){
				t++;
			}
		}
		if(t==2){
			//	printf(" %d ",j);
			c=prime(n,j,0);
			if(c!=0){
				printf(" %d ",j);
				printf(" %d \n",c);
			}
		}
	}
	return 0;
    }
    int prime(int p,int q,int r){
	if(p%q==0){
		r++;
		prime(p/q,q,r);
	}
	else{
	return r;
    }
    }