You are given two integers $$$n$$$, $$$m$$$. Please determine if there exists a positive integer $$$s$$$ such that the following conditions are true:
$$$^\dagger$$$ A positive integer $$$a$$$ is called a palindrome when it reads the same when the order of digits is reversed.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The only line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n,m \le 10^8$$$) — the number of digits and the sum of digits.
For each test case, if there exists a valid integer $$$s$$$, print "YES"; otherwise, print "NO".
You can output the answer in any case (For example, the strings "yEs", "yes", "Yes", and "YeS" will be recognized as positive responses).
77 108 107 1510 2090 10010 782 5
YESYESYESYESYESYESNO
In the first test case, $$$2\,112\,112$$$ satisfies all four conditions:
Therefore, $$$2\,112\,112$$$ can be an answer.
In the second test case, it can be shown that there is no integer $$$s$$$ which satisfies all the conditions.
In the fourth test case, $$$1\,232\,222\,321$$$ can be an answer.
There are $$$x$$$ interviewers numbered from $$$1$$$ to $$$x$$$. Each of the interviewers can conduct at most $$$y$$$ interviews per day. An interview consists of $$$z$$$ different interviewers interviewing one participant.
Calculate the maximum number of participants that can be interviewed in a day (in other words, interviews that can be conducted in a day) and output any one of the schemes.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases.
For each test case:
For each test case,
If there are multiple schemes, you can output any.
33 1 23 2 24 10 5
1 1 2 3 1 2 2 3 1 3 0
This is the easy version of the problem. The only difference is that $$$q=1$$$, $$$l=1$$$ and $$$r=n$$$ in this version.
You are given an array $$$a$$$ of length $$$n$$$. Note $$$$$$s(l,r) = \sum_{i=l}^{r} \sum_{j=i}^{r} \prod_{k=i}^j a_k$$$$$$
where $$$\prod_{k=i}^j a_j$$$ is defined as the product of all elements in the array $$$a$$$ from index $$$i$$$ to $$$j$$$, i.e. $$$(a_i \times a_{i+1} \times ... \times a_j)$$$.
You need to handle $$$q$$$ queries. Each query gives two numbers $$$l$$$, $$$r$$$ $$$(1 \le l \le r \le n)$$$, and you should output $$$s(l,r)$$$.
For each query, you need to output the value modulo $$$10^9+7$$$.
The first line contains the number of test cases $$$t$$$ $$$(1 \leq t \leq 10^5)$$$.
For each test case:
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^{6}$$$.
For each query, output ina new line — the value of $$$s(l,r)$$$ modulo $$$10^9+7$$$.
23 12 4 31 34 11000000000 1000000000 1000000000 10000000001 4
53 1834
In the first test case, $$$a=[2,4,3]$$$ and you need to calculate $$$s(1,3)$$$ in the first query.
For $$$i = 1$$$: $$$$$$ \begin{align*} j = 1: & \quad \prod_{k=1}^{1} a_k = 2 \\ j = 2: & \quad \prod_{k=1}^{2} a_k = 2 \times 4 = 8 \\ j = 3: & \quad \prod_{k=1}^{3} a_k = 2 \times 4 \times 3 = 24 \\ \end{align*} $$$$$$
For $$$i = 2$$$: $$$$$$ \begin{align*} j = 2: & \quad \prod_{k=2}^{2} a_k = 4 \\ j = 3: & \quad \prod_{k=2}^{3} a_k = 4 \times 3 = 12 \\ \end{align*} $$$$$$
For $$$i = 3$$$: $$$$$$ \begin{align*} j = 3: & \quad \prod_{k=3}^{3} a_k = 3 \\ \end{align*} $$$$$$
Thus, $$$s(1,3) = 2+8+34+4+12+3 = 53$$$.
Given two integers $$$n$$$ and $$$m$$$, find any permutation of length $$$n$$$ such that the following conditions hold. $$$$$$ \begin{cases} \gcd(p_i,p_{i+1}) \neq m \ (1 \le i \le n-1) \\ (p_i+p_{i+1}) \mod m \neq 0 \ (1 \le i \le n-1) \\ \end{cases} $$$$$$
The first line contains the integer $$$t$$$ ($$$1 \le t \le 10^5)$$$ — the number of test cases.
For each test case:
It's guaranteed that the sum of $$$n+m$$$ overall test cases doesn't exceed $$$ 10^6$$$.
For each test case, if there is no such permutation, print $$$-1$$$. Otherwise, print any valid permutation that satisfies the condition.
34 45 79 7
1 2 3 4 1 3 2 4 5 1 8 3 2 9 4 5 6 7
This is the hard version of the problem. The only difference is that $$$1\le q \le 2 \cdot 10^6$$$, $$$1 \le l \le r \le n$$$ in this version.
You are given an array $$$a$$$ of length $$$n$$$. Note $$$$$$s(l,r) = \sum_{i=l}^{r} \sum_{j=i}^{r} \prod_{k=i}^j a_k$$$$$$
where $$$\prod_{k=i}^j a_j$$$ is defined as the product of all elements in the array $$$a$$$ from index $$$i$$$ to $$$j$$$, i.e. $$$(a_i \times a_{i+1} \times ... \times a_j)$$$.
You need to handle $$$q$$$ queries. Each query gives two numbers $$$l$$$, $$$r$$$ $$$(1 \le l \le r \le n)$$$, and you should output $$$s(l,r)$$$.
For each query, you need to output the value modulo $$$10^9+7$$$.
The first line contains the number of test cases $$$t$$$ $$$(1 \leq t \leq 10^5)$$$.
For each test case:
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$, and the sum of $$$q$$$ over all test cases does not exceed $$$2 \cdot 10^6$$$.
For each query, output ina new line — the value of $$$s(l,r)$$$ modulo $$$10^9+7$$$.
23 12 4 31 34 31000000000 1000000000 1000000000 10000000001 42 34 4
53 1834 35 1000000000
In the first test case, $$$a=[2,4,3]$$$ and you need to calculate $$$s(1,3)$$$ in the first query.
For $$$i = 1$$$: $$$$$$ \begin{align*} j = 1: & \quad \prod_{k=1}^{1} a_k = 2 \\ j = 2: & \quad \prod_{k=1}^{2} a_k = 2 \times 4 = 8 \\ j = 3: & \quad \prod_{k=1}^{3} a_k = 2 \times 4 \times 3 = 24 \\ \end{align*} $$$$$$
For $$$i = 2$$$: $$$$$$ \begin{align*} j = 2: & \quad \prod_{k=2}^{2} a_k = 4 \\ j = 3: & \quad \prod_{k=2}^{3} a_k = 4 \times 3 = 12 \\ \end{align*} $$$$$$
For $$$i = 3$$$: $$$$$$ \begin{align*} j = 3: & \quad \prod_{k=3}^{3} a_k = 3 \\ \end{align*} $$$$$$
Thus, $$$s(1,3) = 2+8+34+4+12+3 = 53$$$.
For an array $$$b$$$ of length $$$l$$$, a ranking random pick is defined as follows: from the non-decreasing sorted version of array $$$b$$$ (denoted as array $$$c$$$), exactly one element is selected, where the probability of selecting $$$c_i$$$ is given by $$$\frac{i}{1 + 2 + \dots + l}$$$.
Alice and Bob have an array $$$a$$$ of length $$$n$$$ and a fair coin. Initially, Alice's score is $$$0$$$.
If array $$$a$$$ is non-empty, the coin is flipped:
Calculate the expected value of Alice's score. Output the answer modulo $$$998\,244\,353$$$.
Formally, let $$$M = 998\,244\,353$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{M}$$$. Output the integer equal to $$$p \cdot q^{-1} \bmod M$$$. In other words, output such an integer $$$x$$$ that $$$0 \le x \lt M$$$ and $$$x \cdot q \equiv p \pmod{M}$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 400$$$). The description of the test cases follows.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$.
For each test case, print a single integer — the answer to the problem modulo $$$998\,244\,353$$$.
31223 551000000000 999999999 999999999 1000000000 999999998
1 582309209 588585275
In the first case, Alice has $$$\frac{1}{2}$$$ probability of getting a score of $$$2$$$, and $$$\frac{1}{2}$$$ probability of getting a score of $$$0$$$, so the expected score for Alice is $$$\frac{1}{2} \times 2+\frac{1}{2}\times 0=1$$$.
In the second case, Alice's expected score is $$$\frac{1}{2}\times\frac{1}{3} \times 3+\frac{1}{2}\times\frac{2}{3} \times 5+\frac{1}{2}\times\frac{1}{3} \times \frac{1}{2}\times5+\frac{1}{2}\times\frac{2}{3} \times \frac{1}{2}\times3=\frac{37}{12}$$$.
The game tree for the second case.
Assume there is a positive integer $$$x$$$ and an array $$$a$$$ of size $$$n$$$. In one operation, you can choose any element $$$a_i$$$ $$$(1 \le i \le n)$$$ from the array, then set $$$x:=x- x\mod a_i$$$.
Note $$$f(x)$$$ as the minimum number of operations to make $$$x=0$$$. For a given array $$$a$$$ of size $$$n$$$ and a given integer $$$m$$$, calculate $$$\sum_{i=1}^{m}f(i)$$$.
Input data guarantees that for all $$$x=1,2,\ldots,m$$$, $$$x$$$ can always be reduced to $$$0$$$.
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 10^5)$$$ – the number of test cases.
The first line of each test case contains two integers $$$n$$$, $$$m$$$ $$$(2 \le n \le 2 \cdot 10^5 , 1 \le m \le 10^7)$$$ – the length of set $$$a$$$ and integer $$$m$$$.
The second line of each test case contains $$$n$$$ distinct integers $$$a_1,a_2,...,a_n$$$ $$$(1 \le a_i \le 10^7)$$$.
Input data guarantees that for all $$$x=1,2,\ldots,m$$$, $$$x$$$ can always be reduced to $$$0$$$.
It's guaranteed that the sum of $$$n$$$ doesn't exceed $$$2 \cdot 10^5$$$.
It's guaranteed that the sum of $$$m$$$ doesn't exceed $$$10^7$$$.
For each test case, output an integer in a new line — $$$\sum_{i=1}^{m}f(i)$$$.
24 61 2 3 42 72 5
10 12
In the first test case,
So the answer is $$$1+1+1+2+2+3=10$$$.