Category Archives: Mathematical

Program for Perrin numbers

The Perrin numbers are the numbers in the following integer sequence. 3, 0, 2, 3, 2, 5, 5, 7, 10, 12, 17, 22, 29, 39 … In mathematical terms, the sequence p(n) of Perrin numbers is defined by the recurrence relation P(n) = P(n-2) + P(n-3) for n > 2, with initial values P(0) =… Read More »

Find two prime numbers with given sum

Given an even number (greater than 2 ), print two prime numbers whose sum will be equal to given number. There may be several combinations possible. Print only first such pair. An interesting point is, a solution always exist according to Goldbach’s conjecture. Examples: Input: n = 74 Output: 3 71 Input : n =… Read More »

Right-Truncatable Prime

A Right-truncatable prime is a prime which remains prime when the last (“right”) digit is successively removed. For example, 239 is right-truncatable prime since 239, 23 and 2 are all prime. There are 83 right-truncatable primes. The task is to check whether the given number (N > 0) is right-truncatable prime or not. Examples: Input:… Read More »

Program for Chocolate and Wrapper Puzzle

Given following three values, the task is to find the total number of maximum chocolates you can eat. money : Money you have to buy chocolates price : Price of a chocolate wrap : Number of wrappers to be returned for getting one extra chocolate. It may be assumed that all given values are positive… Read More »