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:
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.
- Number of digits in the nth number made of given four digits
- Find Nth number in a sequence which is not a multiple of a given number
- Program for nth Catalan Number
- Find nth Magic Number
- Nth Even Fibonacci Number
- Nth Square free number
- Program to find last two digits of Nth Fibonacci number
- Find nth Fibonacci number using Golden ratio
- Find nth number that contains the digit k or divisible by k.
- Find Nth even length palindromic number formed using digits X and Y
- Nth non-Square number
- Find the Nth Mosaic number
- Program to find the nth Kynea number
- Find Nth number of the series 1, 6, 15, 28, 45, .....
- Program to find the Nth Harmonic Number
- Program to find the Nth number of the series 2, 10, 24, 44, 70.....
- Nth number made up of odd digits only
- Find nth Hermite number
- New Algorithm to Generate Prime Numbers from 1 to Nth Number
- Program to delete Nth digit of a Number
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.