Ramen Packs

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

요약
각 n에 대해 서로 다른 a^2 꼴과 2b^2 꼴의 합으로 n을 나타낼 수 있는지 판정하고, 가능하면 사용한 팩을 출력한다.
난이도

보통10점 중 6점

유형
수학, 정수론, 그리디, 구현
정답자
아직 제출이 없습니다

문제

Thomas wants to buy nn cups of ramen from Liza. She has two brands that he likes: brand A and brand B. Each brand sells packs of ramen in varying sizes. For each integer k≥1k \ge 1, there is a brand A pack of size kk that contains k2k^2 cups of ramen, and a brand B pack of size kk that contains 2k22k^2 cups of ramen. Liza has exactly one pack of each type left in stock. Your task is to determine how Thomas can purchase exactly nn cups of ramen from Liza, or state that such a thing is not possible.

Note that you do not need to minimize the number of packs.

입력

The first line of the input contains a single integer tt (1≤t≤1041 \le t \le 10^4) --- the number of test cases. The description of the test cases follows.

Each test case consists of a single line containing one integer nn (1≤n≤1091 \le n \le 10^9), the number of ramen cups that Thomas wants from Liza.

출력

For each test case, output a single line.

If it is not possible for Thomas to buy nn cups of ramen from Liza, simply print 00.

Otherwise, print a positive integer kk, followed by a list of kk pack types. A \it{pack type} is a letter (either A or B) indicating the brand of the ramen pack followed by a positive integer indicating its size. The sum of the number of cups over all packs should be nn, and no pack type may appear more than once.

힌트

In the first test case, Thomas buys just the A1A1 pack from Liza for a total of 12=11^2 = 1 cups.

In the second test case, Thomas can buy the A1A1 and A3A3 packs from Liza for a total of 12+32=101^2 + 3^2 = 10 cups.

In the third test case, Thomas can buy the A2A2 and B2B2 packs from Liza for a total of 22+2\*22=122^2 + 2\*2^2 = 12 cups.

In the fourth test case, Thomas can buy the A3A3, B2B2, B1B1, and A1A1 packs from Liza for a total of 32+2\*22+2\*12+12=203^2 + 2\*2^2 + 2\*1^2 + 1^2 = 20 cups.

예제1

  1. 예제 1

    입력
    4
    1
    10
    12
    20
    
    예상 출력
    1 A1
    2 A1 A3
    2 A2 B2
    4 A3 B2 B1 A1