P13085 [HackerEarth] turing and the magic board
普及
题目描述

Turing loves playing board games. Recently he played a game on the internet, that he found interesting.

You are given a square board of length N. Each unit box in the board is to be filled with a gold coin. All the players have infinite gold coins in a bank but they will be allowed to withdraw only a maximum of N coins at each turn. In each turn, they have to withdraw at least 1 coin. After withdrawing the coins, they need to place all of them on the board. Moreover, they have to fill the boxes consecutively row after row and column after column starting from the first box.

In formal terms, if the boxes were to be labelled 1 to N^2 row-wise, then any box k (that belongs to 1 to N^2) can only be filled if all boxes labelled 1 to (k-1) are filled.

It is randomly selected who, among the player and the computer, starts first. The player to fill the last box wins.

Turing’s younger brother had started playing this game. He is as proficient in this game as the computer. It is his turn. Since Turing is interested in board games, he would like to predict whether his younger brother would win or not.

Constraints:

1 ≤ T ≤ 1000

0 ≤ N ≤ 1000

0 ≤ k < N*N

Input:

First line indicates the number of test cases T.

Then T lines follow, each containing N (the length of the square board) and k (the number of boxes already filled).

Output:

Print who will win the game.

0, if Computer wins

1, if Player wins
Register for IndiaHacksSAMPLE INPUT
2
4 0
3 1

SAMPLE OUTPUT
1
0

Register for IndiaHacks

输入格式

见题面

输出格式

见题面

样例输入
388 519 72054 276 24593 48 586 445 65349 634 214562 564 216338 328 48675 539 22361 715 421522 705 213461 837 463587 766 254594 583 13882 348 58915 396 38345 135 7722 315 26519 480 121393 297 38722 599 235477 786 130185 128 10328 182 3814 761 385097 95 6438 443 64444 413 22604 286 62398 747 253147 678 74013 34 276 368 87664 538 228194 790 373013 242 28072 316 74766 178 18622 612 8714 425 149043 571 205357 545 280751 767 533274 613 199551 344 12466 76 2348 813 380861 225 44614 617 228043 499 242194 68 4123 503 133849 239 18796 62 717 355 1367 773 504756 401 15331 329 67766 666 14001 690 11944 612 202936 502 249147 190 97 232 8689 804 544869 764 145495 21 5 570 80286 338 67954 424 45259 433 123411 8 36 62 2299 472 49310 513 163375 128 1380 318 16656 256 15962 670 190246 708 395257 532 37979 737 188119 285 43291 127 7725 409 54705 629 66399 219 16241 65 2568 288 49715 242 45703 89 2477 396 138293 313 54352 308 15650 374 108062 768 405629 798 525351 774 582242 437 177582 96 8952 686 225252 77 1572 596 238917 419 118801 837 652948 155 7278 345 30444 726 295013 437 30931 32 846 360 890 188 796 774 512416 711 250850 332 95514 527 208240 3 6 313 53441 140 16555 797 627804 708 416870 373 107797 736 529634 101 2636 523 54061 375 95730 166 8305 511 89789 838 416224 701 397209 499 82580 578 102076 301 23662 415 26124 94 3718 653 173560 553 212811 244 54867 515 69243 8 45 556 31913 311 44163 259 62716 132 11599 354 32087 657 300261 450 97813 589 209313 596 277566 427 135921 605 74490 805 296026 415 66461 836 69445 709 268246 359 101162 461 160617 377 8005 646 388548 287 78555 576 325182 322 69 649 303580 248 46515 384 50841 405 42589 64 3092 536 18137 809 567194 723 220755 687 49248 329 74923 142 10824 338 19754 449 193141 257 59995 803 581488 442 176274 40 1040 243 9326 598 94106 647 262011 407 77826 454 13335 181 18616 280 31994 729 499760 486 133557 469 40663 128 6212 603 128969 333 109426 278 60665 404 74776 778 136709 819 76200 608 98144 427 121828 275 38659 622 201398 449 159460 558 266512 745 182408 439 123846 177 1981 601 29678 186 23005 657 196752 99 3610 95 4393 178 216 643 123782 770 446549 191 22319 262 66083 734 146597 185 26586 278 55544 725 15350 613 41994 518 187196 153 19403 538 282056 481 22044 340 69250 829 344421 723 2096 538 268039 8 47 3 3 12 20 294 76715 419 104259 520 189735 603 204271 437 152945 736 386744 294 82057 713 400280 382 56403 584 116041 805 467238 148 7509 346 50267 541 182044 584 236903 321 8601 63 3531 1 0 274 62282 105 9611 195 19785 614 118011 506 9713 578 4190 770 211396 408 156245 15 15 543 292213 26 674 789 73098 27 158 39 112 239 12509 831 262345 721 298093 458 95758 247 50647 719 298465 789 574769 30 457 84 6464 839 314728 388 54600 619 185186 12 122 338 23497 143 7875 366 58388 494 5375 129 16540 603 36043 601 245 50 606 837 193402 242 18913 104 2065 619 233178 664 327049 635 36623 654 401373 236 1135 843 650073 603 24741 838 87620 32 610 783 321392 789 577281 718 65157 330 9693 227 19810 812 541897 292 6833 428 131710 63 1990 628 189391 179 5721 99 9269 556 306273 780 22721 270 64474 752 294555 680 258431 62 2521 85 6454 499 234912 278 35913 641 217092 447 173262 760 461796 601 193815 461 107024 722 156750 351 78919 576 103425 218 35228 333 81963 288 51047 136 14489 37 31 56 351 611 25749 397 46499 218 32207 790 130344 588 28445 835 526591 720 291755 843 385276 301 54174 671 263040 655 425997 723 51461 407 63255 607 76347 314 79850 294 47123 231 40952 646 166559 690 283662 660 257888 452 95374 717 489474 598 263750 712 392161 524 139569 732 42109 777 102369 512 244758 703 79275 97 7370 252 40018 411 5202 237 16601 166 3925 38 509 674 44460 792 74909 51 1023 496 53485 679 426389 456 131941 589 280775 411 39196 806 151088 690 461665 601 333569 528 98586 659 57206 459 85982 241 47112 122 5698 221 44504 696 91818 613 261198 269 21015 683 171816 248 27046 347 28130
样例输出
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1