Not able to solve this question

/*A Boston number is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding 1 ). The first few such numbers are 4,22 ,27 ,58 ,85 ,94 and 121 . For example, 378 = 2 × 3 × 3 × 3 × 7 is a Boston number since 3 + 7 + 8 = 2 + 3 + 3 + 3 + 7. Write a program to check whether a given integer is a Boston number.

Input Format
There will be only one line of input:N , the number which needs to be checked.

Constraints
1 < N < 2,147,483,647 (max value of an integer of the size of 4 bytes)

Output Format
1 if the number is a Boston number. 0 if the number is a not Boston number.

Sample Input
378
Sample Output
1
Explanation
Self Explanatory

*/

#include
using namespace std;

int findPrimeSum(int n)
{
int j;
int sum=0;
for(int i=2;i<n;i++)
{
for(j=2;j<i;j++)
{
if(i%j==0)
{
break;
}
}
if(i==j)
{
sum=sum+i;
}
}

return sum;

}

int findNumSum(int n)
{
int sum;
int no;
while(n>0)
{
no=n%10;
sum=sum+no;

    n=n/10;

}
return sum;

}
int main()
{

long int n;
cin>>n;

int x=findPrimeSum(n);
int y=findNumSum(n);

if(x==y)
{
cout<<1;
}
else{
cout<<0;
}

return 0;
}

I am not able to find the approach to solve this question please tell me the approach and what changes I should do in this code

hi @anandsingh3210
The Question is Very Simple but needs a little extra concentration. As many students do not consider that in the Question it said the sum of digits of the given number is Equals to the sum of digits of its prime numbers is equal only when the number is Boston number.
For e.g…, n = 22
Prime Factors = 2 x 11
Sum of Digits = 2 + 2 = 4
Sum of Digits of Factors = 2 + (1 + 1) -> 4
Hence it is a Boston number.

Algorithm
  1. Generate All prime Factors of the number.
  2. Write a Function that calculates the sum of digits of passed number.
  3. Pass each generated Prime Factor to this digits sum function till you can generate prime factors.
  4. At last equate your sum with the sum of digits of given number.
    4.1 If yes print 1.
    4.2 otherwise print 0.

Note -> Make your code a little Efficient otherwise you will get TLE with brute force approach. By making code efficient is either you need to make your prime factor generator efficient or prime checker efficient in order to pass the test cases.

refer this code -->

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.

#include
#include
#include
#include
#include
using namespace std;

int main() {
int n, sum=0, sum_n=0;
cin>>n;
int temp=n;

while(temp>0){
    sum_n=sum_n+(temp%10);
    temp/=10;
}

while (n%2 == 0){
    sum+=2;
    n = n/2;
}
for (int i = 3; i <= sqrt(n); i = i+2){
    while (n%i == 0){
        int temp1=i;
        while(temp1>0){
            sum=sum+(temp1%10);
            temp1/=10;
        }
        n = n/i;
    }
}
if (n > 2){
    while(n>0){
        sum=sum+(n%10);
        n/=10;
    }
}

if(sum_n==sum)
    cout<<"1";
else
    cout<<"0";
return 0;

}