Given an Octal number N. The task is to write a program to check if the Decimal representation of the given octal number N is divisible by 7 or not.
Input: N = 112 Output: NO Equivalent Decimal = 74 7410 = 7 * 10 1 + 4 * 100 1128 = 1 * 82 + 1 * 81 + 2 * 80 Input: N = 25 Output: YES Decimal Equivalent = 21
The idea is to note that, 8 % 7 will return 1. Thus, when we expand octal representation and take its modulo 7 all powers of 8 in individual terms will reduce to 1. So, if the sum of all the digits in octal representation is divisible by 7 then, the corresponding decimal number will be divisible by 7.
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Decimal representation of given binary string is divisible by 10 or not
- Decimal representation of given binary string is divisible by 20 or not
- Convert a given Decimal number to its BCD representation
- Check if an Octal number is Even or Odd
- Check if number is palindrome or not in Octal
- Program for Octal to Decimal Conversion
- Program for Decimal to Octal Conversion
- Decimal to octal conversion with minimum use of arithmetic operators
- Check if binary representation of a number is palindrome
- Check if the given number is divisible by 71 or not
- Check if the number is divisible 43 or not
- Check if a number is divisible by 41 or not
- Check if a number is divisible by 31 or not
- Check if a number is divisible by 47 or not
- Check if a number is divisible by 23 or not
- Check if a number is divisible by all prime divisors of another number
- Check a large number is divisible by 16 or not
- Check if the square of a number is divisible by K or not
- Check if a large number is divisible by 75 or not
- Check if a large number is divisible by 25 or not
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.