Modulo 4

시간 제한1초메모리 제한2048 MB

요약
0, 1, |로 이루어진 길이 k의 문자열 가운데 접미사로 2^n-1 값을 갖는 식을 포함하는 것의 개수를 4로 나눈 나머지를 구한다.
난이도

어려움10점 중 8점

유형
조합론, 동적 계획법, 문자열 매칭, 정수론
정답자
아직 제출이 없습니다

문제

Let AA be the set of all arithmetic expressions consisting of the digits 0, 1, and the bitwise OR operator |, starting with 1, such that there is a 1 immediately after each |.

Let B_nB\_n be the subset of all expressions from AA such that their value is equal to 2n−12^n-1 when considering the numbers in the expression in binary.

Let C_nC\_n be the subset of all expressions from AA containing at least one expression from the set B_nB\_n as a suffix. For example, the following expressions are in C_3C\_3: 10011111, 111, 110|1|11, 11|11001|1010|101, and these expressions are not in C_3C\_3: 111|1011, 1, 10|11|11, 1100|10|100.

For given positive integers nn and kk, find the number of expressions from the set C_nC\_n that contain exactly kk digits (and an arbitrary number of |). As the answer may be very large, output it modulo~44.

입력

The input contains t≤10t \le 10 test cases. The value tt is given on the first line of input.

The only line in each test case contains two integers nn and kk (2≤n≤10122 \le n \le 10^{12}, n+2≤k≤2⋅1012n+2 \le k \le 2 \cdot 10^{12}).

출력

For each test case, output the number of expressions from the set C_nC\_n containing exactly kk digits, modulo~44.

힌트

Here are 1414 expressions from the first example:

1111, 1011, 1|111, 111|1, 110|1, 11|11, 10|11, 11|10, 10|1|1, 11|1|1, 1|10|1, 1|11|1, 1|1|10, 1|1|11

예제1

  1. 예제 1

    입력
    4
    2 4
    5 15
    147 10000
    60 150
    
    예상 출력
    2
    0
    1
    3