Given a number, the task is to check if a number is divisible by 6 or not. The input number may be large and it may not be possible to store even if we use long long int.
Input : n = 2112 Output : Yes Input : n = 1124 Output : No Input : n = 363588395960667043875487 Output : No
Since input number may be very large, we cannot use n % 6 to check if a number is divisible by 8 or not, especially in languages like C/C++. The idea is based on following fact.
A number is divisible by 6 it's divisible by 2 and 3. a) A number is divisible by 2 if its last digit is divisible by 2. b) A number is divisible by 3 if sum of digits is divisible by 3.
Below is the implementation based on above steps.
This article is contributed by DANISH_RAZA . If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Number of substrings divisible by 6 in a string of integers
- Check if a large number is divisible by 3 or not
- GCD of more than two (or array) numbers
- Count rotations divisible by 4
- Superperfect Number
- Number of Permutations such that no Three Terms forms Increasing Subsequence
- Check if the first and last digit of the smallest number forms a prime
- Print all substring of a number without any conversion
- Complement of a number with any base b
- Check if Decimal representation of an Octal number is divisible by 7