Register

Login

CODECRAFT LEVEL THREE

Problem 1:

Lucky Numbers

John has recently arrived in Bucharest for the South Eastern European Regional Contest. John is famous for his theory of lucky numbers. That's why all the contestants and spectators are very happy. According to that theory 4 and 7 are lucky digits, and all the other digits are not lucky. A lucky number is a number that contains only lucky digits in decimal notation. A very lucky number is a number that can be expressed as a product of several lucky numbers. A lucky number by itself is considered to be very lucky. For example, numbers 47, 49, 112 are very lucky. Your task is to calculate the number of very lucky numbers that are not less than A and not greater than B. Of course, numbers A and B are given by John.

Input:
The first line of the input contains a single integer T - a number of test cases. Each of the next T lines contains two integers separated by a single space - A and B.

Output:
Output must contain T lines - answers for the test cases. Constrains:
1 <= T <= 7777,
1 <= A <= B <= 1000000000000 (10^12)

Sample Input:
4
1 2
88 99
112 112
1 100

Output:
0
0
1
10

Hint:
Very lucky numbers for the last case are 4, 7, 16, 28, 44, 47, 49, 64, 74 and 77.



Problem 2:

Mahabharat

One of the greatest epics in Indian history is Mahabharat. In this epic, Shakuni plays a key role by intimidating Dhuryodhana to go against the Pandavas resulting in the Great War. The story that still remains hidden is what causes Shakuni to intimidate Dhuryodhana resulting the down fall of Dhuryodhana. Shakuni himself unfolds the story for us.

I was born along with one hundred brothers and enjoyed a huge amount of wealth. Dhuryodhana had an eye over my wealth and wanted to capture it, so he imprisoned me and my brothers. He provided food and water sufficient for only one person. Since, I was the most intelligent of the lot and was keen to take revenge on him; I decided to make sure that I got the food needed to survive. So I framed an idea to get the food.

The idea was to form a circle consisting of me and my brothers and then eliminating the mth person from the circle stating he will not be eligible for the food. The last person still left in the circle would get the food and water. I always made sure that I got the food and water. Also, I wanted to make sure that none of my brothers recognize the pattern of elimination, so I kept changing the value of m every day.

Assume yourself to be the modern-world Shakuni equipped with computers, write a program to obtain the food for yourself given the number of brothers (n) and the elimination number (m).

Input (Standard Input)
The standard input consists of k(at most 5) test cases. First line of the input is the number of test cases. The next k lines each has two numbers n (0 < =32000) and m (0 < =32000) separated by a space, each corresponding to a single test case. n is the number of brothers and m is the elimination value. The First position is numbered "1".

Output (Standard Output)
For each test case, print the position you should take to obtain the food. E.g. for the 23rd position, output the number 23. You should have k lines of output, and no blank lines.













Copyright 2009.©Noesis 2009 
All rights reserved.

UPDATES

!!! Start crafting your code at Codecraft !!!

-Learner Guided for Ecotecture is availabel here.

-Online Registration will be  closed by 4th Sep 09

-Registration fees to be paid on  the spot on 5th Sep 9:30am

-Opening Ceremony -
        5th Sep 09 9:00am

-Events Starts-
        5th Sep 09 10:30am