second and third test case fail.
plz help me to fix this
Boston NUMbers wrong solution why
see if you are following this approach…
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
Generate All prime Factors of the number.
Write a Function that calculates the sum of digits of passed number.
Pass each generated Prime Factor to this digits sum function till you can generate prime factors.
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.
i think my code should give TLE, instead of wrong answer. Because
almost same algorithm i had used, whatever you are explaining.
n can go upta max value of int so its better to use long…
for n= 2050918644
your code output 0 but its a boston number…
Now my code is working.
Your test case helped me to fixed this.
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.