The problem is to check whether the decimal representation of the given binary number is divisible by 20 or not. Take care, the number could be very large and may not fit even in long long int. The approach should be such that there are zero or minimum number of multiplication and division operations. No leading 0’s are there in the input.
Input : 101000 Output : Yes (10100)2 = (40)10 and 40 is divisible by 20. Input : 110001110011100 Output : Yes
Approach: Following are the steps:
- Let the binary string be bin.
- Let the length of bin be n.
- If bin[n-1] == ‘1’, then it is an odd number and thus not divisible by 20.
- Else check if bin[0..n-2] is divisible by 10. Refer this post.
Time Complexity: O(n), where n is the number of digits in the binary number.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Decimal representation of given binary string is divisible by 5 or not
- Decimal representation of given binary string is divisible by 10 or not
- Check if Decimal representation of an Octal number is divisible by 7
- Convert a given Decimal number to its BCD representation
- Maximum splits in binary string such that each substring is divisible by given odd number
- Find value of k-th bit in binary representation
- XOR counts of 0s and 1s in binary representation
- Binary representation of a given number
- Maximum 0's between two immediate 1's in binary representation
- Largest number with binary representation is m 1's and m-1 0's
- 1 to n bit numbers with no consecutive 1s in binary representation.
- 1 to n bit numbers with no consecutive 1s in binary representation
- Binary representation of previous number
- Next greater number than N with exactly one bit different in binary representation of N
- Maximum distance between two 1's in Binary representation of N
- Length of the Longest Consecutive 1s in Binary Representation
- Occurrences of a pattern in binary representation of a number
- Check if all the set bits of the binary representation of N are at least K places away
- Python | Check if binary representation is palindrome
- Prime Number of Set Bits in Binary Representation | Set 1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Mithun Kumar