You are on page 1of 6

A

Arithmancy

Hermione Granger, the most talented witch of her generation, likes to solve various types of mathematical problems in the Arithmancy class. Today, the professor has given her the following task: Find the number of fractions a/b such that1. gcd(a, b) = 1 2. 0 < a/b < 1 3. a * b = (n!) ^ (n!) Where n! denotes the factorial of n and ^ denotes power, i.e. (2!) ^ (2!) = 4. She is quite confident that she can solve it for n 10^7, but then she remembers that she has to study some case history so that she can help Hagrid to win the case of Buckbeak. So, she wants your help to solve the problem. Input There will be one line for each test case containing the number n (1 n 10^7). Input will be terminated by EOF. There will be around 20,000 test cases. Output For each case, print the number of fractions in a separate line. This number may be very large, so print the answer modulo 10,007.

Sample Input
1 2

Output for Sample Input


0 1

[Type text]

Calendar

We know that there are so many calendar systems. For example, Bangla, Christ, Arabic, Chinese etc. This problem is about Decimal calendar. There are 3 months in this calendar. First month is Hundreds. There are 300 days in this month. Second month is Tens. There are 60 days in this month. And this followed by the last month Ones having 5 or 6 days depending on whether this is leap year or not. A Decimal year spans a full Christ calendar. That is 1st Hundreds in Decimal Calendar is 1st January in Christi Calendar. Similarly, 31st December of Christ Calendar is 5th or 6th day of Decimal calendar (depending on whether it is leap year or not). A year in Decimal calendar is leap year if the corresponding Christ year is leap year. For example, the Decimal year corresponding to 2000 Christ year is leap year but 2001 is not, and again 1900 is not leap year too. A year in Christ calendar is leap year if the year is divisible by 400 or divisible by 4 but not by 100. You are given a day in Christ calendar in DD-MMM-YYYY format (DD stands for day, MMM stands for first three letters (in CAPS) of the month and YYYY stands for the year). You are to give the date in Decimal Calendar format. Input First line contains number of test case. Every test case consists of a date in Christ Calendar format in each line. Output You are to output the case number and the date in Decimal Calendar format. Output the date and the month in the Decimal Calendar.

Sample Input
3 01-JAN-1900 10-JAN-1900 16-DEC-1900 Note First three letters for the months are:

Output for Sample Input


Case 1: 1 Hundreds Case 2: 10 Hundreds Case 3: 50 Tens

JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC.

[Type text]

Mr. and Mrs. Ant

Mr. and Mrs. Ant are very hungry. So, they want to collect food as much as they can. They can search for foods simultaneously. To do so, they start from their house and collect all foods together and meet in some place (not necessarily their house). Finally, they eat together. The world of Mr. and Mrs. Ant is a two dimensional grid. Each cell is either the home, or free, or blocked, or contains a food. Two cells are adjacent if they share an edge. In each second, they can move from one cell to another cell simultaneously. One can decide to not to move in some step, while other may move. One cell can be visited many times. Both of them can move into the same cell also. In this problem, the grid is given by an R x C matrix represented by following characters: Character
H F . (dot) # (hash)

Meaning Home of Mr. and Mrs. Ant A food item Free (passable) cell Blocked cell

Remarks Occurs exactly once Occurs at least once, at most 8 times.

Given the grid information, give the minimum amount of time that must be needed for them to collect all the foods and then meet. Input The first line of input will contain T (T 30) denoting the number of cases. Each case starts with two integers R and C (2 R, C 12). Then, R lines follow giving the grid. Output For each case, print the case number, the minimum amount of time (in seconds) that must be needed for them to collect all the foods and meet. If it is impossible to collect all the food items, output -1 (negative one) instead.

Sample Input
2 2 3 H#. .#F 2 6 F#F..# ..H#.F

Output for Sample Input


Case 1: -1 Case 2: 8

[Type text]

Cricinfo

I guess the most visited site of the past 3 months is www.cricinfo.com. First World Cup Cricket, then Australia tour to Bangladesh and now IPL T20. I believe there are lots of cricket fans among you. So I do not need to describe the game rule. But for the purpose of this problem here is short description of scoring. Any rule out of this problem description is not applicable for this problem. For this problem we will use only the following outcomes in a ball:
Possible Outcome in a Ball . 1 2 3 4 6 Wd 1Wd 2Wd 4Wd Nb 1Nb 4Nb 6Nb W Runs 0 1 2 3 4 6 1 2 3 5 1 2 5 7 0 Is the Ball valid? Yes Yes Yes Yes Yes Yes No No No No No No No No Yes

(Wd stands for wide, Nb for No Ball and W for Wicket) In cricinfo we always watch the score card. In cricket an over consists of 6 valid balls. A score card of an over may look like below:
1 . W . Wd Nb . 6

In this over there were 1 wicket and 9 runs. In the last over of second innings of a match, a team requires N runs to win. You are to output number of ways of the outcome of the over. Note that, as you are watching second innings of the match, so it may be possible that he can score N runs in first 4 balls and win the match. That means, it is not necessary to play an entire over to score N runs. Also suppose you do not know how many wickets are already gone. So it may also be possible that after a few wicket falls they are all out. Also note that, if a team scores greater or equal to N runs the team wins and does not play any ball.

[Type text]

Input First line contains number of test case T (T 10000). For each test a line contains N (1 N 10000). Output For every test case, output the case number and number of ways of outcome of the last over where the team needs N runs to win. As the answer can be very big, so output in mod 10000007.

Sample Input
1 1

Output for Sample Input


Case 1: 946

Note Two ways are different if the outcome of a ball in the last over is different.

[Type text]

Pole and Wire

There are N poles along a road side. You have to tie wires to the poles. You can attach two ends of a wire to two different poles. A pole might not have any wire attached to it. A pole also must not have more than one wire attached to it. Two wires must not cross each other but may overlap. For example, suppose there are 5 poles. Say a wire is from pole 1 to pole 4 and another from pole 2 to pole 5. These two wires crossed each other. So such configuration is invalid. But say a wire is from pole 1 to pole 4 and another from pole 2 to pole 3. This is overlap, so it is valid configuration. Input First line of the test file contains number of test cases, T (T 300). For every test case you will be given number of poles N (1 N 10^5). Output For every test case you are to output number of test case and number of ways of valid configuration. As the number of ways is very big you have to output the result in modulo 1,000,003.

Sample Input
2 3 4

Output for Sample Input


Case 1: 4 Case 2: 9

Hint For N = 3, there are 4 possible valid configurations. No wires attached Wire from Pole 1 to Pole 2 Wire from Pole 2 to Pole 3 Wire from Pole 1 to Pole 3

[Type text]

You might also like