CF963A.Alternating Sum

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two integers aa and bb. Moreover, you are given a sequence s0,s1,…,sns_0, s_1, \dots, s_{n}. All values in ss are integers 11 or −1-1. It's known that sequence is kk-periodic and kk divides n+1n+1. In other words, for each k≤i≤nk \leq i \leq n it's satisfied that si=si−ks_{i} = s_{i - k}.

Find out the non-negative remainder of division of ∑i=0nsian−ibi\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i} by 109+910^{9} + 9.

Note that the modulo is unusual!

给你两个整数 aa 和 bb。此外,你被给定一个序列 s0,s1,…,sns_0, s_1, \dots, s_{n}。序列 ss 中所有值均为整数 11 或 −1-1。已知该序列是 kk-周期性的,且 kk 整除 n+1n+1。换言之,对每个满足 k≤i≤nk \leq i \leq n 的 ii,均有 si=si−ks_{i} = s_{i - k}。

求 ∑i=0nsian−ibi\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i} 除以 109+910^{9} + 9 所得的非负余数。

注意:此处取模的模数是非同寻常的!

输入格式

The first line contains four integers n,a,bn, a, b and kk (1≤n≤109,1≤a,b≤109,1≤k≤105)(1 \leq n \leq 10^{9}, 1 \leq a, b \leq 10^{9}, 1 \leq k \leq 10^{5}).

The second line contains a sequence of length kk consisting of characters '+' and '-'.

If the ii-th character (0-indexed) is '+', then si=1s_{i} = 1, otherwise si=−1s_{i} = -1.

Note that only the first kk members of the sequence are given, the rest can be obtained using the periodicity property.

第一行包含四个整数 n,a,bn, a, b 和 kk (1≤n≤109,1≤a,b≤109,1≤k≤105)(1 \leq n \leq 10^{9}, 1 \leq a, b \leq 10^{9}, 1 \leq k \leq 10^{5})。

第二行包含一个长度为 kk 的字符串,由字符 '+' 和 '-' 组成。

若第 ii 个字符(从 0 开始编号)为 '+',则 si=1s_{i} = 1;否则 si=−1s_{i} = -1。

注意:仅给出序列的前 kk 项,其余项可利用周期性性质得到。

输出格式

Output a single integer — value of given expression modulo 109+910^{9} + 9.

输出一个整数——给定表达式的值对 109+910^{9} + 9 取模的结果。

输入输出样例

  • 输入#1

    2 2 3 3
    +-+

    输出#1

    7
  • 输入#2

    4 1 5 1
    -

    输出#2

    999999228

说明/提示

In the first example:

(∑i=0nsian−ibi)(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}) = 2230−2131+20322^{2} 3^{0} - 2^{1} 3^{1} + 2^{0} 3^{2} = 7

In the second example:

(∑i=0nsian−ibi)=−1450−1351−1252−1153−1054=−781≡999999228(mod109+9)(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}) = -1^{4} 5^{0} - 1^{3} 5^{1} - 1^{2} 5^{2} - 1^{1} 5^{3} - 1^{0} 5^{4} = -781 \equiv 999999228 \pmod{10^{9} + 9}.

在第一个例子中:

(∑i=0nsian−ibi)(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}) = 2230−2131+20322^{2} 3^{0} - 2^{1} 3^{1} + 2^{0} 3^{2} = 7

在第二个例子中:

(∑i=0nsian−ibi)=−1450−1351−1252−1153−1054=−781≡999999228(mod109+9)(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}) = -1^{4} 5^{0} - 1^{3} 5^{1} - 1^{2} 5^{2} - 1^{1} 5^{3} - 1^{0} 5^{4} = -781 \equiv 999999228 \pmod{10^{9} + 9}。

输入解题思路,AI测评打分。不知道怎么写?

首页