Primes and Queries

아직 제출이 없습니다시간 제한90초메모리 제한1024 MB

문제

You are given a prime number PP.

Let's define V(x)V(x) as the degree of PP in the prime factorization of xx. To be clearer, if V(x)=yV(x)=y then xx is divisible by PyP^y, but not divisible by Py+1P^{y+1}. Also we define V(0)=0V(0)=0.

For example, when P=3P=3, and x=45x=45, since 45=53245=5 \cdot 3^2, therefore V(45)=2V(45)=2.

You are also given an array AA with NN elements. You need to process QQ queries of 22 types on this array:

  • type 11 query: 1 pos val - assign a value valval to the element at pospos, i.e. A_pos:=valA\_{pos} := val
  • type 22 query: 2 S L R - print _i=LRV(A_iS(A_imodP)S)\displaystyle\sum\_{i=L}^{R}{V(A\_i^S - (A\_i \bmod P)^S)}.

입력

The first line of the input gives the number of test cases, TTTT test cases follow.

The first line of each test case contains 33 space separated positive integers NNQQ and PP - the number of elements in the array, the number of queries and a prime number.

The next line contains NN positive integers A_1A\_1, A_2A\_2, \cdots, A_NA\_N representing elements of array AA.

Each of the next QQ lines describes a query, and contains either

  • 33 space separated positive integers: 1 pos val
  • or 44 space separated positive integers: 2 S L R

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is a list of the answers for each query of type 22.

제한

  • 1T1001 \le T \le 100
  • 2P1092 \le P \le 10^9
  • PP is a prime number.
  • 1posN1 \le pos \le N
  • 1LRN1 \le L \le R \le N

For at most 10 cases:

  • 1N5×1051 \le N \le 5 \times 10^5
  • 1Q1051 \le Q \le 10^5

For the remaining test cases:

  • 1N1031 \le N \le 10^3
  • 1Q1031 \le Q \le 10^3

There will always be at least one query of type 22.

힌트

In Sample Case #1

The first query is a query of type 22, where S=3S=3, L=3L=3, R=4R=4. Let's calculate the result for this query:

i=3i=3, V(623(62mod2)3)=3V(62^3 - (62 \bmod 2)^3)=3

i=4i=4, V(673(67mod2)3)=1V(67^3 - (67 \bmod 2)^3)=1

_i=34V(A_i3(A_imodP)3)=3+1=4\displaystyle\sum\_{i=3}^{4}{V(A\_i^3 - (A\_i \bmod P)^3)} = 3+1 = 4

The second query is of type 11, where we need to assign 6969 to A_1A\_1, so our array AA now becomes: 69 94 62 67 91.