Please help me in finding the error in logic and help me in rectifying it.
Here is my code.
Please help me in finding the error in logic and help me in rectifying it.
Here is my code.
Hi @sinchan1509_1a917d7b6cc3cbb9,
According to the problem,
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
So, if the number is 26 = 2 x 13
Then, you need to add 2 + 1 + 3 and not 2 + 13.
sum += counter;
change above line to
sum += sumofdigits(counter);
Where sumofdigits function is defined as,
int sumofdigits(int n){
int ans = 0;
while(n){
ans += n%10;
n /= 10;
}
return ans;
}
Second error is Boston number is a composite number. So prime numbers are not Boston numbers ( 5, 13, 7, …etc)
Thank you so much I got it.
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.