#P13251. [GCJ 2014 #1B] New Lottery Game

    ID: 15117 远端评测题 3000~5000ms 1024MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>2014分治记忆化搜索数位 DP位运算Google Code Jam

[GCJ 2014 #1B] New Lottery Game

题目描述

The Lottery is changing! The Lottery used to have a machine to generate a random winning number. But due to cheating problems, the Lottery has decided to add another machine. The new winning number will be the result of the bitwise-AND operation between the two random numbers generated by the two machines.

To find the bitwise-AND of XX and YY, write them both in binary; then a bit in the result in binary has a 11 if the corresponding bits of XX and YY were both 11, and a 00 otherwise. In most programming languages, the bitwise-AND of XX and YY is written X&YX \& Y.

For example:

  • The old machine generates the number 7=01117 = 0111.
  • The new machine generates the number 11=101111 = 1011.
  • The winning number will be $(7 \text{ AND } 11) = (0111 \text{ AND } 1011) = 0011 = 3$.

With this measure, the Lottery expects to reduce the cases of fraudulent claims, but unfortunately an employee from the Lottery company has leaked the following information: the old machine will always generate a non-negative integer less than AA and the new one will always generate a non-negative integer less than BB.

Catalina wants to win this lottery and to give it a try she decided to buy all non-negative integers less than KK.

Given AA, BB and KK, Catalina would like to know in how many different ways the machines can generate a pair of numbers that will make her a winner.

Could you help her?

输入格式

The first line of the input gives the number of test cases, TT. TT lines follow, each line with three numbers AA BB KK.

输出格式

For each test case, output one line containing "Case #xx: yy", where xx is the test case number (starting from 11) and yy is the number of possible pairs that the machines can generate to make Catalina a winner.

5
3 4 2
4 5 2
7 8 5
45 56 35
103 143 88
Case #1: 10
Case #2: 16
Case #3: 52
Case #4: 2411
Case #5: 14377

提示

Sample Explanation

In the first test case, these are the 10 possible pairs generated by the old and new machine respectively that will make her a winner: $\langle 0,0\rangle, \langle 0,1\rangle, \langle 0,2\rangle, \langle 0,3\rangle, \langle 1,0\rangle$, $\langle 1,1\rangle, \langle 1,2\rangle, \langle 1,3\rangle, \langle 2,0\rangle$ and 2,1\langle 2,1\rangle. Notice that 0,1\langle 0,1\rangle is not the same as 1,0\langle 1,0\rangle. Also, although the pair 2,2\langle 2, 2\rangle could be generated by the machines it wouldn't make Catalina win since (2 AND 2)=2(2 \text{ AND } 2) = 2 and she only bought the numbers 00 and 11.

Limits

  • 1T1001 \leq T \leq 100.

Small dataset(8 Pts)

  • Time limit: 60 3 seconds.
  • 1A10001 \leq A \leq 1000.
  • 1B10001 \leq B \leq 1000.
  • 1K10001 \leq K \leq 1000.

Large dataset(24 Pts)

  • Time limit: 120 5 seconds.
  • 1A1091 \leq A \leq 10^9.
  • 1B1091 \leq B \leq 10^9.
  • 1K1091 \leq K \leq 10^9.