#P16234. [蓝桥杯 2026 省 B] 循环右移

[蓝桥杯 2026 省 B] 循环右移

Background

All Lanqiao Cup 2026 provincial contest testdata on this site are created by Luogu and may differ from the official data. They are for learning reference only.

Problem Description

Given three integers N,X,YN, X, Y. Please compute how many integer arrays AA of length NN satisfy the following conditions:

  1. Each element AiA_i in array AA satisfies X≤Ai≤YX \le A_i \le Y.
  2. For any contiguous subarray of AA, after performing one cyclic right shift operation on it, the new subarray is exactly the same as the original subarray.

Cyclic right shift: For a contiguous subarray of length kk, [B1,B2,…,Bk][B_1, B_2, \dots, B_k], performing one cyclic right shift means transforming it into [Bk,B1,B2,...,Bk−1][B_k, B_1, B_2, ..., B_{k-1}] (i.e., move the last element to the front, and shift the other elements one position to the right in their original order).

Input Format

The first line contains an integer TT, indicating the number of test cases.

The next TT lines each contain three integers N,X,YN, X, Y separated by spaces.

Output Format

For each test case, output one line containing an integer, representing the number of arrays AA that satisfy the conditions.

3
3 1 2
5 10 10
2 5 3
2
1
0

Hint

Constraints

For 30%30\% of the test cases, 1≤T≤201 \le T \le 20, 1≤N≤1001 \le N \le 100, 1≤X,Y≤1001 \le X, Y \le 100.

For 100%100\% of the test cases, 1≤T≤1031 \le T \le 10^3, 1≤N≤10181 \le N \le 10^{18}, 1≤X,Y≤10181 \le X, Y \le 10^{18}.

Translated by ChatGPT 5