Given a number N in decimal base, the task is to find the sum of digits of the number in any base B.
Input: N = 100, B = 8
(100)8 = 144
Sum(144) = 1 + 4 + 4 = 9
Input: N = 50, B = 2
(50)2 = 110010
Sum(110010) = 1 + 1 + 0 + 0 + 1 + 0 = 3
Approach: Find unit digit by performing modulo operation on number N by base B and updating the number again by N = N / B and update sum by adding the unit digit at each step.
Below is the implementation of above approach
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.
- Given a number N in decimal base, find number of its digits in any base (base b)
- Find the Nth digit from right in base B of the given number in Decimal base
- C++ program to find all numbers less than n, which are palindromic in base 10 and base 2.
- Find the total count of numbers up to N digits in a given base B
- Check if a given number can be represented in given a no. of digits in any base
- Check if the number is even or odd whose digits and base (radix) is given
- Add two integers of different base and represent sum in smaller base of the two
- Convert all substrings of length 'k' from base 'b' to decimal
- Convert from any base to decimal and vice versa
- Find most significant bit of a number X in base Y
- Find the length of factorial of a number in any given base
- Find the Largest N digit perfect square number in Base B
- All possible numbers of N digits and base B without leading zeros
- Program to find the last digit of X in base Y
- Check if a N base number is Even or Odd
- Pandigital number in a given base
- Complement of a number with any base b
- Check if a number is in given base or not
- Check whether a number has consecutive 0's in the given base or not
- Largest value of x such that axx is N-digit number of base b
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.