some hint?
i know in this question , need to count prime number.
I am getting WA in TestCase 1, 2 ,3
@Vipin_coder,
No you don’t need to check for prime numbers buddy. You have to check for divisibility with the given numbers, that’s it.
Suggested Approach:
- check for all sub-strings of the given string of digits, starting from the all strings of length 1 and then gradually checking for the strings of increasing size:
1.1. check if the sub-string is CB number: for this, create a function
1.1.1. if sub-string is 1 or 0 return false.
1.1.2. if sub-string is any of the {2,3,5,7,11,13,17,19,23,29}, then return true.
1.1.3. if sub-string is divisible by any of the {2,3,5,7,11,13,17,19,23,29}, then return false.
1.1.4. return false
1.2. now if it is a substring:
1.2.1. call a function that marks the index as visited for indexes which are part of that CB number.
1.3. increment the count for CB number.
- Print the count
mean i need to count first fro 1 length of substrings, then for all 2 length of substring and so on.??
@Vipin_coder,
Yes but mark in case you are taking the substring and that is a CB number then make sure you mark the visited for the indexes.
Sample input:
6
441441
Correct Answer: 2
Here 41,41 are the CB numbers, hence the answer will be 2.
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.