Algebra on Segment

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

문제

Consider a prime number pp.

All operations below will be performed in the multiplicative group modulo pp.

Given an array of size nn, process qq queries of two types:

  • "1 ll rr xx": multiply all elements of the segment \[l;r]\[l; r] by xx;
  • "2 ll rr": find the order of the subgroup generated by the set of elements from the segment \[l;r]\[l; r].

To revise some of the definitions, see the notes below.

입력

In the first line of input, there are three integers pp, nn, qq: the prime number, the size of the array and the number of queries (2p<1092 \le p < 10^{9}, pp is prime, 1n1051 \le n \le 10^{5}, 1q1051 \le q \le 10^{5}).

The second line of input contains the initial array aa of size nn (1a_i<p1 \le a\_{i} < p).

The next qq lines describe the queries.

A query of the first type is described as "1 ll rr xx": multiply all elements of the segment \[l;r]\[l; r] by xx (1lrn1 \le l \le r \le n, 1x<p1 \le x < p).

A query of the second type is described as "2 ll rr": find the order of the subgroup generated by the set of elements from the segment \[l;r]\[l; r] (1lrn1 \le l \le r \le n).

출력

For each query of the second type, print the answer to it on a separate line.

힌트

In this section, we will give definitions for all terms from group theory which appear in the statement. All the definitions are conventional, so feel free to skip the section if you are familiar with the basics of group theory.

A group is a set with associative binary operation. The group is closed under its operation: for any two elements aa and bb of the group, aba \circ b is also an element of this group, where \circ is the binary operation. There exists the identity element (equivalent of 11 for multiplication), and for every element there exists an inverse.

A multiplicative group modulo prime number pp is defined as follows. The elements of the group are non-zero remainders modulo pp: that is, 1,2,,p11, 2, \ldots, p-1. The operation is multiplication modulo pp. It is easy to see that it is a group.

A subgroup is a subset HH of group GG which itself is a group for the same operation as in GG: in particular, it is closed under the binary operation.

A subgroup generated by a set: for any subset SGS \subseteq G, S\langle S \rangle is the smallest subgroup GG which contains SS. This subgroup is unique.

The order of the group is the number of elements in it.