logo AlgoBeat OnlineJudge
登录 注册

#216669. [GKS 2018 #C] Kickstart Alarm

内存限制:1024 MiB 时间限制:6000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Shil has a very hard time waking up in the morning each day, so he decides to buy a powerful alarm clock to Kickstart his day. This Alarm is called a Kickstart Alarm. It comes pre-configured with powerful wakeup calls. Before going to bed, the user programs the clock with a Parameter Array consisting of the values , , ..., . In the morning, the clock will ring times, with the -th wakeup call having power .

To calculate , the alarm generates all the contiguous subarrays of the Parameter Array and calculates the summation of the -th exponential-power of all contiguous subarrays. The -th exponential-power of subarray , , ..., is defined as . So is just the summation of the -th exponential-power of all the contiguous subarrays of the Parameter Array.

For example, if , and , then the -th exponential-power of would be calculated as follows:

  • 2-nd exponential-power of
  • 2-nd exponential-power of
  • 2-nd exponential-power of
  • 2-nd exponential-power of
  • 2-nd exponential-power of
  • 2-nd exponential-power of

so the total is .

Tonight, Shil is using his Kickstart Alarm for the first time. Therefore, he is quite worried about the sound the alarm might make in the morning. It may wake up the neighbors, or, worse yet, it may wake up the whole planet! However, calculating the power of each wakeup call is quite difficult for him. Given and the Parameter Array , , ..., , can you help him by calculating the summation of power of each wakeup call: ?

输入格式

The first line of the input gives the number of test cases, T. test cases follow. Each test case consists of one line with nine integers , , , , , , , and . is the length of array , is the number of wakeup calls. Rest of the values are parameters that you should use to generate the elements of the array , as follows.

Use the recurrences below to generate and for to :

  • modulo .
  • modulo .

We define modulo , for all to .

输出格式

For each test case, output one line containing Case #x: POWER, where x is the test case number (starting from 1) and POWER is the summation of , for to . Since POWER could be huge, print it modulo ().

样例

样例输入 1

2
2 3 1 2 1 2 1 1 9
10 10 10001 10002 10003 10004
10005 10006 89273

样例输出 1

Case #1: 52
Case #2: 739786670

数据范围与提示

In Sample Case #1, the Parameter Array is [3, 2]. All the contiguous subarrays are [3], [2], [3, 2].

For i = 1:

  • 1-st Exponential-power of [3] =
  • 1-st Exponential-power of [2] =
  • 1-st Exponential-power of [3, 2] =

So is 12.

For i = 2:

  • 2-nd Exponential-power of [3] =
  • 2-nd Exponential-power of [2] =
  • 2-nd Exponential-power of [3, 2] =

So is 16.

For i = 3:

  • 3-rd Exponential-power of [3] =
  • 3-rd Exponential-power of [2] =
  • 3-rd Exponential-power of [3, 2] =

So is 24.

Limits

.

.

.

.

.

.

.

.

Small dataset (Test set 1 - Visible)

.

.

Large dataset (Test set 2 - Hidden)

.

.