Given a number n, find the sum of digits of n when represented in different bases from 2 to n-1.
Input : 5 Output : 2 3 2 Representation of 5 is 101, 12, 11 in bases 2 , 3 , 4 . Input : 7 Output : 3 3 4 3 2
- As the given question wants the sum of digits in different bases, first we have to calculate the given number of different bases and add each digit to the number of different bases.
- So, to calculate each number’s representation we will take the mod of given number by the base in which we want to represent that number.
- Then, we have to add all those mod values as the mod values obtained will represent that number in that base.
- Finally, the sum of those mod values gives the sum of digits of that number.
Below are implementations of this approach
1 4 2 4 3 2
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.
- Sum of the digits of a number N written in all bases from 2 to N/2
- Quickly convert Decimal to other bases in Python
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Minimum digits to be removed to make either all digits or alternating digits same
- Check if a number can be written as sum of three consecutive integers
- Check if a number can be written as a sum of 'k' prime numbers
- Find the prime numbers which can written as sum of most consecutive primes
- Smallest number with given sum of digits and sum of square of digits
- Even digits Sum and Odd digits sum divisible by 4 and 3 respectively
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Count different numbers that can be generated such that there digits sum is equal to 'n'
- Paytm Interview Experience | Set 7 (Written Test Hyderabad)
- Find if n can be written as product of k numbers
- Written version of Logical operators in C++
- Find smallest number with given number of digits and sum of digits
- Find the Largest number with given number of digits and sum of digits
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Check if the sum of digits of number is divisible by all of its digits
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.