Lucky Numbers

A number is called lucky if the sum of its digits, as well as the sum of the squares of its digits is a prime number. How many numbers between a and b inclusive, are lucky? For example, a=20 and b=25. Each number is tested below: digit digit squares value sum squares sum 20 2 4,0 4 21 3 4,1 5 22 4 4,4 8 23 5 4,9 13 24 6 4,16 20 25 7 4,25 29 We see that two numbers, 21, 23 and

Unfair Game

You are playing a game of Nim with a friend. The rules are are follows: 1) Initially, there are N piles of stones. Two players play alternately. 2) In each turn, a player can choose one non empty pile and remove any number of stones from it. At least one stone must be removed. 3) The player who picks the last stone from the last non empty pile wins the game. It is currently your friend's turn. You suddenly realize that if your friend was to play optimally in that position, you would

Oil Wel

Mr. Road Runner bought a piece of land in the middle of a desert for a nominal amount. It turns out that the piece of land is now worth millions of dollars as it has an oil reserve under it. Mr. Road Runner contacts the ACME corp to set up the oil wells on his land. Setting up oil wells is a costly affair and the charges of setting up oil wells are as follows. The rectangular plot bought by Mr. Road Runner is divided into r * c blocks. Only some blocks are suitable for setting up the oil well

Find the Seed

A company needs random numbers for its operation. N random numbers have been generated using N numbers as seeds and the following recurrence formula: The numbers used as seeds are F(N-1),F(N-2),...,F(1),F(0). F(K) is the Kth term of the recurrence. Due to a failure on the servers, the company lost its seed numbers. Now they just have the recurrence formula and the previously generated N random numbers. The company wants to recover the numbers used as seeds, so they have hired you for d

The Blacklist

A new gangster is trying to take control of the city. He makes a list of his N adversaries (e.g. gangster 1, gangster 2, ... gangster N-1, gangster N) and plans to get rid of them. K mercenaries are willing to do the job. The gangster can use any number of these mercenaries. But he has to honor one condition set by them: they have to be assigned in such a way that they eliminate a consecutive group of gangsters in the list, e.g. gangster i, gangster i+1, ..., gangster j-1, gangster j, where t