CF1797E.Li Hua and Array

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Li Hua wants to solve a problem about φ\varphi — Euler's totient function. Please recall that φ(x)=i=1x[gcd(i,x)=1]\varphi(x)=\sum\limits_{i=1}^x[\gcd(i,x)=1] . ,^{\dagger,\ddagger}

He has a sequence a1,a2,,ana_1,a_2,\cdots,a_n and he wants to perform mm operations:

  • "1 ll rr " ( 1lrn1\le l\le r\le n ) — for each x[l,r]x\in[l,r] , change axa_x into φ(ax)\varphi(a_x) .
  • "2 ll rr " ( 1lrn1\le l\le r\le n ) — find out the minimum changes needed to make sure al=al+1==ara_l=a_{l+1}=\cdots=a_r . In each change, he chooses one x[l,r]x\in[l,r] , change axa_x into φ(ax)\varphi(a_x) . Each operation of this type is independent, which means the array doesn't actually change.

Suppose you were Li Hua, please solve this problem.

^\dagger gcd(x,y)\gcd(x,y) denotes the greatest common divisor (GCD) of integers xx and yy .

^\ddagger The notation [cond][\textrm{cond}] equals 11 if the condition cond\textrm{cond} is true, and 00 otherwise.

输入格式

The first line contains two integers nn and mm ( 1n,m1051\le n,m\le 10^{5} ) — the number of elements in the array and the number of operations to process, respectively.

The second line contains nn integers a1,a2,,ana_{1},a_{2},\cdots ,a_{n} ( 1ai51061\le a_{i}\le 5\cdot 10^{6} ) — the elements of the array.

Next mm lines, each line contains three integers ti,li,rit_{i},l_{i},r_{i} ( ti{1,2},1lirint_i\in\{1,2\},1\le l_i\le r_i\le n ) — the ii -th operation.

输出格式

For each "2 ll rr ", output the answer in an separate line.

输入输出样例

  • 输入#1

    5 4
    8 1 6 3 7
    2 1 5
    2 3 4
    1 1 3
    2 3 4

    输出#1

    10
    2
    1

说明/提示

Denote φk(x)={x,k=0φ(φk1(x)),k>0\varphi^k(x)=\begin{cases}x,&k=0\\\varphi(\varphi^{k-1}(x)),&k > 0\end{cases} .

At first, a=[8,1,6,3,7]a=[8,1,6,3,7] .

To make sure a1=a2=a3=a4=a5a_1=a_2=a_3=a_4=a_5 , we can change aa to a=[φ3(8),φ0(1),φ2(6),φ2(3),φ3(7)]=[1,1,1,1,1]a'=[\varphi^3(8),\varphi^0(1),\varphi^2(6),\varphi^2(3),\varphi^3(7)]=[1,1,1,1,1] , using 3+0+2+2+3=103+0+2+2+3=10 changes.

To make sure a3=a4a_3=a_4 , we can change aa to a=[φ0(8),φ0(1),φ1(6),φ1(3),φ0(7)]=[8,1,2,2,7]a'=[\varphi^0(8),\varphi^0(1),\varphi^1(6),\varphi^1(3),\varphi^0(7)]=[8,1,2,2,7] , using 0+0+1+1+0=20+0+1+1+0=2 changes.

After "1 11 33 ", aa is changed to a=[φ1(8),φ1(1),φ1(6),φ0(3),φ0(7)]=[4,1,2,3,7]a=[\varphi^1(8),\varphi^1(1),\varphi^1(6),\varphi^0(3),\varphi^0(7)]=[4,1,2,3,7] .

To make sure a3=a4a_3=a_4 , we can change aa to a=[φ0(4),φ0(1),φ0(2),φ1(3),φ0(7)]=[4,1,2,2,7]a'=[\varphi^0(4),\varphi^0(1),\varphi^0(2),\varphi^1(3),\varphi^0(7)]=[4,1,2,2,7] , using 0+0+0+1+0=10+0+0+1+0=1 change.

首页