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

#SP0000090. Petya và các ước số (Petya and Divisors)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Petya và các ước số (Petya and Divisors)

Petya and Divisors

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Process nn queries in order. Query ii gives xi,yix_i,y_i. Count the positive divisors dd of xix_i that divide none of the preceding numbers xi−yi,…,xi−1x_{i-y_i},\ldots,x_{i-1}. If yi=0y_i=0, all positive divisors of xix_i count. The previous numbers are part of the same query sequence.

Input

The first line contains nn. The ii-th of the following nn lines contains xi,yix_i,y_i, indexed from 11.

Output

Print nn lines; line ii gives the answer for query ii.

Subtasks

  • Subtask 1 (20 points): 1≤n≤301\le n\le 30; 1≤xi≤1001\le x_i\le 100; 0≤yi≤i−10\le y_i\le i-1 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤xi≤50001\le x_i\le 5000; 0≤yi≤i−10\le y_i\le i-1 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤xi≤1000001\le x_i\le 100000; 0≤yi≤i−10\le y_i\le i-1 for every 1≤i≤n1\le i\le n.

Examples

Input

6
4 0
3 1
5 2
6 2
18 4
10000 3

Output

3
1
1
2
2
22

Explanation

Query 1: all divisors 1,2,41,2,4 of 44 count, giving 33. Query 2: only divisor 33 of 33 does not divide the preceding 44, giving 11. Query 3: only divisor 55 of 55 avoids both 44 and 33, giving 11. Query 4: for 66, the acceptable divisors are 2,62,6, giving 22. Query 5: for 1818, the acceptable divisors are 9,189,18, giving 22. Query 6 has 2222 divisors of 1000010000 which divide none of 5,6,185,6,18.