All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian.
Elections in Bytetown are coming soon!
Candidate Boris is going to have a small walk. Bytetown can be represented as N-dimensional cube with edge size D. Initially Boris stands in cell with coordinates (0, 0, ... 0) and his destination is cell (D-1, D-1,... D-1). His route consists of chain of the cells, where each pair of consecutive cells differs in exactly one coordinate by 1 and sum of coordinates strictly increases during his walk. Note that Boris walks through the cells not points.
But not all the people in Bytetown are going to vote for Boris. Some of them are sure that Boris is a liar and bribetaker and they will tell it to Boris if they meet him. Boris doesn't like such people and avoids them. He knows that at cell with coordinares (i0, i1,..., iN-1) he will meet (i0^ i1^...^iN-1)x(i0+ i1+...+ iN-1) such people (in other words XOR-sum of coordinates times arithmetic sum of coordinates). Try to help him to find minimal number of unfriendly people he will have to meet.
The first line of the input contains an integer T denoting the number of test cases. Each of the next T lines contain two integer N and D.
Output T lines. Every line should contain one integer - the minimal number of unfriendly people among all the possible routes Boris will have to meet for the corresponding test case.
- 1 ≤ T ≤ 20
- 1 ≤ N ≤ 10
- Total number of cells in one cube doesn't exceed 216
Subtask #1[26 points]: N = 1
Subtask #2[29 points]: N = 2
Subtask #3[45 points]: N > 2
ExampleInput: 4 1 2 1 3 2 2 2 3 Output: 1 5 1 10
|Tags||dynamic-programming, easy-medium, implementation, ltime20, pavel1996|
|Time Limit:||1 - 2 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.