#abc241e. E - Putting Candies

E - Putting Candies

Score : 500500 points

问题描述

你得到一个长度为 NN 的序列 A=(A0,A1,,AN1)A=(A_0,A_1,\ldots,A_{N-1})

有一个初始时为空的盘子。Takahashi 将会重复进行以下操作 KK 次:

  • XX 为盘子上糖果的数量。他会再往盘子上添加 A(XmodN)A_{(X \bmod N)} 个糖果。这里,XmodNX\bmod N 表示 XX 除以 NN 后的余数。

请计算在 KK 次操作后盘子上有多少个糖果。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a sequence A=(A0,A1,,AN1)A=(A_0,A_1,\ldots,A_{N-1}) of length NN.
There is an initially empty dish. Takahashi is going to repeat the following operation KK times.

  • Let XX be the number of candies on the dish. He puts A(XmodN)A_{(X\bmod N)} more candies on the dish. Here, XmodNX\bmod N denotes the remainder when XX is divided by NN.

Find how many candies are on the dish after the KK operations.

Constraints

  • 2N2×1052 \leq N \leq 2\times 10^5
  • 1K10121 \leq K \leq 10^{12}
  • 1Ai1061 \leq A_i\leq 10^6
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

A0A_0 A1A_1 \ldots AN1A_{N-1}

Output

Print the answer.

Sample Input 1

5 3
2 1 6 3 1

Sample Output 1

11

The number of candies on the dish transitions as follows.

  • In the 11-st operation, we have X=0X=0, so A(0mod5)=A0=2A_{(0\mod 5)}=A_0=2 more candies will be put on the dish.
  • In the 22-nd operation, we have X=2X=2, so A(2mod5)=A2=6A_{(2\mod 5)}=A_2=6 more candies will be put on the dish.
  • In the 33-rd operation, we have X=8X=8, so A(8mod5)=A3=3A_{(8\mod 5)}=A_3=3 more candies will be put on the dish.

Thus, after the 33 operations, there will be 1111 candies on the dish. Note that you must not print the remainder divided by NN.

Sample Input 2

10 1000000000000
260522 914575 436426 979445 648772 690081 933447 190629 703497 47202

Sample Output 2

826617499998784056

The answer may not fit into a 3232-bit integer type.

update @ 2024/3/10 10:23:42