#524. 余数问题

余数问题

题目描述

You are given an array a a consisting of 500000 500000 integers (numbered from 1 1 to 500000 500000 ). Initially all elements of a a are zero.

You have to process two types of queries to this array:

  • 1 x y 1\ x\ y — increase ax a_x by y y ;
  • 2 x y 2\ x\ y — compute iR(x,y)ai \sum\limits_{i \in R(x, y)} a_i , where R(x,y) R(x,y) is the set of all integers from 1 1 to 500000 500000 which have remainder y y modulo x x . Can you process all the queries?

题意

一个长度为 5105 5*10^5 的数组,初始为空,支持两种操作。

操作 111 x y 1\ x\ y 表示将 ax a_x 增加 y y

操作 2 2 2 x y 2\ x\ y ,表示统计所有下标模 x x y y 的数的和,一共有 5105 5*10^5 次操作。(1x500000) (1\leq x\leq 500000)

输入格式

The first line contains one integer q q (1q500000) (1≤q≤500000) — the number of queries.

Then q q lines follow, each describing a query. The i i -th line contains three integers ti t_i , xi x_i and yi y_i (1ti2) (1≤t_i≤2) . If ti=1 t_i = 1 , then it is a query of the first type, 1xi500000 1≤x_i≤500000 , and 1000yi1000−1000≤y_i≤1000. If ti=2t_i=2, then it it a query of the second type, 1xi5000001≤x_i≤500000, and 0yi<xi0≤y_i<x_i.

It is guaranteed that there will be at least one query of type 2 2 .

输出格式

For each query of type 2 2 print one integer — the answer to it.

样例

样例输入

5
1 3 4
2 3 0
2 4 3
1 4 -4
2 1 0

样例输出

4
4
0