in my algo i am genearting numbers from i till j continuosly but it fails 2 cases out of 9.
Finding cb numbers 2 cases fail
Hello @piyush.bansal8158625,
Let’s read a part of the question again.
- 2,3,5,7,11,13,17,19,23,29 are CB numbers.
- Any number not divisible by the numbers in point 2( Given above) are also CB numbers.
Do you think that the function int fact(int a){} is checking for the above cases?
Example:
if a is 49.
Is it a CB number?
No, coz it is divisible by 7.
Do you think that your code is really checking for this?
Correct it.
Hope, this would help.
Give a like, if you are satisfied.
The cb number is basically a any of the prime numbers or I am reading cb number wrong.
and my code functions is checking for prime number. As 49 is not a prime number it will return 0
Hello @piyush.bansal8158625,
No, you can are correctly checking for all possible CB numbers.
It is actually skipping the CB numbers:
Example:
11
44166181111
Your Output:
2
it detected: {44166181, 11} as CB numbers
Expected Output:
4
{41, 61, 11, 11}
Hope, this would help.
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.
Still tell me how to pass numbers to my cb function so that I cant find all cb numbers
If you would print num, then you would realise that your code is initially checking for all the subarrays/substrings that are starting from index i=0. And after detecting a CB number, it makes i=j. Correct?
Like in the example mentioned in my previous reply, it detected two CB numbers though actually there were 4 CB numbers:
Detected CB numbers:
44166181
11
Actual:
41
61
11
11
Solution:
- Check for all the substrings starting from smallest size i.e. 1, then gradually increase the size.
- Also, use an array to mark the indexes that are used in the CB numbers that are already detected.
I have modified your code. Read the comments for better understanding:
Give a like, if this helps.