A number is a Repunit in base B if it can be represented as a string of three or more 1’s in a base >= 2.
Check if N is a Repunit number
Given an integer N, the task is to check if N is a Repunit number in base B.
Input: N = 31, B = 5
31 can be written as 111 base in 5
Input: N = 5, B = 2
5 is 101 in base 2
Approach: We will count the number of one’s in the base B of a given number N and also count the number of digits in the base B of a given number N. If they are same, print “YES” else print “NO”.
N = 31, B = 5
31 can be written as 111 base in 5, So number of one’s in base B of a given number N = 3 and number of digits in the base B of a given number N = 3
Since both are equal hence 31 is a Repunit number in base 5.
Below is the implementation of the 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.
- Ugly Numbers
- Program for Fibonacci numbers
- Print all Good numbers in given range
- Carmichael Numbers
- Lucas Numbers
- Emirp numbers
- Equidigital Numbers
- Program for Perrin numbers
- Sum of Perrin Numbers
- Reversible numbers
- Triangular Numbers
- Express a number as sum of consecutive numbers
- Rectangular (or Pronic) Numbers
- Sum of cubes of first n even numbers
- Sum of cubes of first n odd natural numbers
- Hailstone Numbers
- Program to find sum of first n natural numbers
- Taxicab Numbers
- Find position of the given number among the numbers made of 4 and 7
- Tribonacci Numbers
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.