#P15566. [COCI 2025/2026 #5] 重量 / Težina

    ID: 17430 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>二分O2优化COCI(克罗地亚)2026整除分块

[COCI 2025/2026 #5] 重量 / Težina

Background

The full score for this problem is 7070.

Problem Description

In front of the strongman Karlo at the gym, there is an array aa of length nn, where aia_i represents the weight of the ii-th item. He can also use kk different “weight types”, numbered 1,2,…,k1,2,\dots,k.

For each weight type from 11 to kk, Karlo considers every item in the array in order and follows the process below:

  1. Compute the result of dividing the item’s weight by the current weight type (discard the fractional part), and record this integer.
  2. Multiply this integer by “the item’s weight +2+2”. If the resulting integer is greater than 10810^8, replace it with 10810^8.
  3. Add up the integers obtained for all items to get the “strength value” of this weight type.

Karlo wants to know the sum of the strength values of all weight types. Please help him solve this problem.

Input Format

The first line contains two natural numbers n,kn,k (1≤n,k≤1051 \le n,k \le 10^5), representing the number of items and the number of weight types.

The second line contains nn integers a1,a2,…,ana_1,a_2,\dots,a_n (1≤ai≤1051 \le a_i \le 10^5).

Output Format

Output one integer on a single line, representing the required total sum.

1 2
2
12
2 1
3 4
39
7 19
1 2 3 4 5 6 7
414

Hint

Sample Explanation

Explanation for Sample #2:

In this sample, there is only weight type 11:

  • 3→3⋅(3+2)=153 \to 3 \cdot (3+2)=15
  • 4→4⋅(4+2)=244 \to 4 \cdot (4+2)=24

The total sum is 3939.

Subtasks

Subtask Score Constraints
11 1717 k≤300k \le 300
22 1919 The number of distinct values in array aa is at most 300300
33 3434 No additional constraints

Translated by ChatGPT 5