PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000162. Truy vấn GCD có cập nhật (GCD Queries with Updates)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Truy vấn GCD có cập nhật (GCD Queries with Updates)

GCD Queries with Updates

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Maintain a 1-indexed array a1,…,ana_1,\ldots,a_n of positive integers while processing qq operations in order:

  • 1 i g: Print the number of indices j≠ij\ne i such that gcd⁡(ai,aj)=g\gcd(a_i,a_j)=g in the current array.
  • 2 i x: Permanently assign ai=xa_i=x. Later queries must use the updated value.

A query of type 1 does not modify the array. Never include j=ij=i in the count, even if g=aig=a_i.

Input

The first line contains n,qn,q. The second line contains nn integers aia_i. Each of the next qq lines contains either 1 i g or 2 i x. All indices are 1-based.

Output

Print a count on a separate line for each query of type 1.

Subtasks

  • Subtask 1 (20 points): 1≤n≤101 \le n \le 10; 1≤q≤201 \le q \le 20; 1≤ai,g,x≤1001 \le a_i,g,x \le 100.
  • Subtask 2 (30 points): 1≤n,q≤50001 \le n,q \le 5000; 1≤ai,g,x≤1051 \le a_i,g,x \le 10^5.
  • Subtask 3 (50 points): 1≤n,q≤1051 \le n,q \le 10^5; 1≤ai,g,x≤1061 \le a_i,g,x \le 10^6.

Examples

Input

4 4
12 8 9 18
1 1 12
1 4 2
2 2 6
1 4 6

Output

0
1
2

Explanation

Initially a=[12,8,9,18]a=[12,8,9,18]. No other value has GCD 1212 with a1=12a_1=12, so the first answer is 00. Only 88 has GCD 22 with a4=18a_4=18, so the next answer is 11. After assigning a2=6a_2=6, the array becomes [12,6,9,18][12,6,9,18]. Both 1212 and 66 have GCD 66 with 1818; 99 does not. The final answer is 22.