Help me in solving PRIMFACT05 problem

My issue

approach for this question in easy way

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	int n;
	cin>>n;
	bool flag=true;
	int i;
	int count=0;
	for(i=2;i*i<=n;i++){
	    if(n%i==0){
	        flag=false;
	        for(int j=2;j*j<=n;j++){
	            if(i%j!=0){
	                count++;
	                cout<<count<<endl;
	            }
	        }
	       // cout<<count<<endl;
	    }
	}
	if(n==1){
	    cout<<"1"<<endl;
	}
	if(flag){
	    cout<<"1"<<endl;
	}
// 	else{
// 	    int prime=0;
// 	    for(int i=2;i*i<=n;i++){
// 	        if(n)
// 	    }
// 	}
	}
	return 0;
}

Learning course: Chitkara DSA Bootcamp
Problem Link: CodeChef: Practical coding for everyone

@niyati1137be21
Plzz refer the following solution for better understanding.

#include <iostream>
#include <unordered_set>
using namespace std;

int distinctPrimeFactors(int n) {
    unordered_set<int> primes;
    int x = n;
    for (int i = 2; i * i <= x; i++) {
        while (n % i == 0) {
            n /= i;
            primes.insert(i);
        }
    }
    
    if (n > 2) {
        primes.insert(n);
    }
    
    return primes.size();
}

int main() {
    int t;
    cin >> t;
    
    for (int i = 0; i < t; i++) {
        int num;
        cin >> num;
        cout << distinctPrimeFactors(num) << endl;
    }
    
    return 0;
}