code : - https://onlinegdb.com/vGxbKPb4W
Code failing test cases
hi @akashagarwal1321
refer this code–>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
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;
}
hi @akashagarwal1321
what ques says is a Boston number is a number in which the sum of whose digits is the sum of the digits of its prime factors.
while(temp>0)
{
sum_n=sum_n+(temp%10);
temp/=10;
}
this part calculates the sum of digits of the number given…
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;
}}
this part calculates the prime factors and add the digits of prime factors in another variable…
method used here is same as https://www.geeksforgeeks.org/print-all-prime-factors-of-a-given-number/
then we check if both the sum are same then the number is prime else not…
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.