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

#SP0000240. Đếm nguyên tố trên đoạn có cập nhật (Counting Primes)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm nguyên tố trên đoạn có cập nhật (Counting Primes)

Counting Primes

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array aa of nn positive integers, indexed from 11 to nn. Perform qq operations in their given order:

  • 0 l r v: assign the same value vv to every entry al,…,ara_l,\ldots,a_r. This operation replaces values; it does not add vv.
  • 1 l r: count the entries in the inclusive range [l,r][l,r] whose current values are prime.

A prime is an integer greater than 11 with no positive divisors other than 11 and itself. All earlier assignments affect subsequent queries.

Input

  • The first line contains two integers n,qn,q.
  • The second line contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n.
  • Each of the following qq lines is 0 l r v or 1 l r, with 1≤l≤r≤n1\le l\le r\le n.

Output

For each operation 1 l r, print on its own line the number of prime-valued entries in [l,r][l,r] at that moment. Assignment operations produce no output.

Subtasks

  • Subtask 1 (20 points): 1≤n≤301\le n\le30; 1≤q≤401\le q\le40; 2≤ai≤1002\le a_i\le100; assignment value 2≤v≤1002\le v\le100; every query satisfies 1≤l≤r≤n1\le l\le r\le n.

  • Subtask 2 (30 points): 1≤n≤10001\le n\le1000; 1≤q≤30001\le q\le3000; 2≤ai≤1062\le a_i\le10^6; assignment value 2≤v≤1062\le v\le10^6; every query satisfies 1≤l≤r≤n1\le l\le r\le n.

  • Subtask 3 (50 points): 1≤n≤1041\le n\le10^4; 1≤q≤2⋅1041\le q\le2\cdot10^4; 2≤ai≤1062\le a_i\le10^6; assignment value 2≤v≤1062\le v\le10^6; every query satisfies 1≤l≤r≤n1\le l\le r\le n.

Examples

Input

5 3
78 2 13 12 3
1 1 2
0 4 4 5
1 1 5

Output

1
4

Explanation

Initially the array is [78,2,13,12,3][78,2,13,12,3]. Query 1 1 2 examines 7878 (composite) and 22 (prime), so the first answer is 1. Assignment 0 4 4 5 changes only position 44 from 1212 to 55, producing [78,2,13,5,3][78,2,13,5,3]; it prints nothing. Query 1 1 5 now sees four prime-valued entries (22, 1313, 55, and 33), so the second answer is 4.