A Carol number is an integer of the form 4n – 2(n+1) – 1. An equivalent formula is (2n-1)2 – 2.
An Interesting Property :
For n > 2, the binary representation of the n-th Carol number is n-2 consecutive one’s, a single zero in the middle, and n + 1 more consecutive one’s. Example, n = 4 carol number is 223 and binary of 223 is 11011111, here n-2 = 4-2 = 2 consecutive one’s in starting then single 0 in middle and then n + 1 = 4 + 1 = 5 consecutive one’s after it.
Given a number n, the task is to find the n’th Carol Number. First few carol numbers are 1, 7, 47, 223, 959… etc.
Input : n = 2 Output: 7 Input : n = 4 Output: 223
This article is contributed by Shashank Mishra ( Gullu ). 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.
- Count number of triplets with product equal to given number with duplicates allowed
- Count number of trailing zeros in Binary representation of a number using Bitset
- Find minimum number to be divided to make a number a perfect square
- Number of times the largest perfect square number can be subtracted from N
- Number of possible permutations when absolute difference between number of elements to the right and left are given
- Given number of matches played, find number of teams in tournament
- Number of digits to be removed to make a number divisible by 3
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Minimum number of given powers of 2 required to represent a number
- Find the smallest number whose digits multiply to a given number n
- Queries on sum of odd number digit sums of all the factors of a number
- Super Ugly Number (Number whose prime factors are in given set)
- Print a number strictly less than a given number such that all its digits are distinct.
- Find maximum number that can be formed using digits of a given number
- Find the largest good number in the divisors of given number N
Improved By : jit_t