A polite number is a positive integer that can be written as the sum of two or more consecutive positive integers. Given N, find the N-th polite number.
Input : 4 Output : 7 Explanation: The first 3 are 3(1+2), 5(2+3), 6(1+2+3). Input : 7 Output : 11 Explanation: 3, 5, 6, 7, 9, 10, 11.
There exist an interesting pattern that only powers of 2 are not present in series of Polite numbers. Based on this fact, there exist below formula (Lambek–Moser theorem) for N-th polite number.
Here to find Nth polite number we have to take n as n+1 in the above equation
The inbuilt log function computes log base-e, so dividing it by log base-e 2 will give log base-2 value.
Given below is the implementation of the above approach:
- 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
- Given number of matches played, find number of teams in tournament
- Smallest number dividing minimum number of elements in the array | Set 2
- Largest number dividing maximum number of elements in the array
- Smallest number dividing minimum number of elements in the Array
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Number of ways to split a binary number such that every part is divisible by 2
- 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
- Find the total number of composite factor for a given number
- Find the number of ways to divide number into four parts such that a = c and b = d
- Count number of ways to divide a number in 4 parts
- Find the largest good number in the divisors of given number N
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.