#P15353. [COCI 2025/2026 #4] 冰激凌 / Sladoled

    ID: 17317 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>背包 DPCOCI(克罗地亚)2026bitset

[COCI 2025/2026 #4] 冰激凌 / Sladoled

Problem Description

There are nn sets S1∼SnS_1\sim S_n, all initially empty.

There are qq operations. In each operation, given positive integers a,ba,b, it means setting Sa←Sa∪{b}S_a\gets S_a\cup \{b\}, and then you need to answer the following question:

  • Assume every number in SaS_a can be used an unlimited number of times. By selecting some numbers from SaS_a (at least 11 number) and adding them up, how many positive integers in 1∼500001\sim 50000 can be obtained?

Input Format

The first line contains two positive integers n,qn,q (1≤n≤1001\le n\le 100, 1≤q≤1051\le q\le 10^5).

The next qq lines each contain two positive integers a,ba,b (1≤a≤n1\le a\le n, 1≤b≤500001\le b\le 50000), describing one operation.

Output Format

Output qq lines. Each line contains one positive integer, representing the answer.

1 2
1 3
1 5
16666
49996
2 4
2 35625
1 25139
1 37795
2 17791
1
1
2
3

Hint

Sample Explanation

Explanation for sample 1:

  • After the first operation, you can obtain multiples of 33. Among those not greater than 5000050000, there are 1666616666.
  • After the second operation, the only numbers that cannot be obtained are 1,2,4,71,2,4,7.

Subtasks

Subtask ID Full Score Constraints
11 1616 n=1,q≤20n=1,q\le 20
22 3333 q≤100q\le 100
33 6161 No additional constraints.

Translated by ChatGPT 5