Padovan SequencePadovan Sequence similar to Fibonacci sequence with similar recursive structure. The recursive formula is, P(n) = P(n-2) + P(n-3) P(0) = P(1) = P(2) = 1 Fibonacci Sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55...... Spiral of squares with side lengths which follow the Fibonacci sequence. Padovan Sequ
4 min read
Aliquot SequenceGiven a number n, the task is to print its Aliquot Sequence. Aliquot Sequence of a number starts with itself, remaining terms of the sequence are sum of proper divisors of immediate previous term. For example, Aliquot Sequence for 10 is 10, 8, 7, 1, 0. The sequence may repeat. For example, for 6, we
8 min read
Moser-de Bruijn SequenceGiven an integer 'n', print the first 'n' terms of the Moser-de Bruijn Sequence. Moser-de Bruijn sequence is the sequence obtained by adding up the distinct powers of the number 4 (For example, 1, 4, 16, 64, etc). Examples: Input : 5 Output : 0 1 4 5 16 Input : 10 Output : 0 1 4 5 16 17 20 21 64 65
12 min read
Recaman's sequenceGiven an integer n. Print first n elements of Recamanâs sequence. Recaman's Sequence starts with 0 as the first term. For each next term, calculate previous term - index (if positive and not already in sequence); otherwise, use previous term + index.Examples: Input: n = 6Output: 0, 1, 3, 6, 2, 7Expl
8 min read
Sum of the sequence 2, 22, 222, .........Given an integer n. The task is to find the sum of the following sequence: 2, 22, 222, ......... to n terms. Examples : Input: n = 2Output: 24Explanation: For n = 2, the sum of first 2 terms are 2 + 22 = 24Input: 3Output: 246Explanation: For n = 3, the sum of first 3 terms are 2 + 22 + 222 = 246Usin
8 min read
n-th term in series 2, 12, 36, 80, 150....Given a series 2, 12, 36, 80, 150.. Find the n-th term of the series.Examples : Input : 2 Output : 12 Input : 4 Output : 80 If we take a closer look, we can notice that series is sum of squares and cubes of natural numbers (1, 4, 9, 16, 25, .....) + (1, 8, 27, 64, 125, ....).Therefore n-th number of
3 min read