Boston numbers problem

THe code is failing in some of the test cases

#include
#include<math.h>
using namespace std;
int digitSum(int n){
int sum = 0;
while(n>0){
int temp = n%10;
sum += temp;
n /= 10;

}
return sum;

}
int prime(int n){

int temp = sqrt(n);
int sumprime = 0;
if(n==1 || n==0)
    return 0;
if(n==2 || n==3)
	return n;
else{
	for(int i = 2; i<temp; i++){
		while(n%i == 0){
			sumprime += digitSum(i);
			n /= i;
		}
	}
}
return sumprime;

}
int main() {
long long n;
cin>>n;
int sumofdigit = digitSum(n);
int sumofprime = prime(n);
if(sumofdigit == sumofprime){
cout<<“1”<<endl;
}
else{
cout<<“0”<<endl;
}
return 0;
}

Hey @Username_cb
there are 2 corrections here
1st one is it should be <=temp
and second one is add ths after end of for loop if(n>1)sumprime+=digitSum(n);
this will consider the case when n have prime no >temp as its prime factor

So overall:
for(int i = 2; i<=temp; i++){
while(n%i == 0){
sumprime += digitSum(i);
n /= i;
}
}
if(n>1) sumprime += digitSum(n);

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.