等比数列求和一定要分类讨论!!!!!!!!!!!!

 #include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define ull unsigned long long
using namespace std; const int N=1e6+;
const int M=+;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
const int mod=1e9 + ; LL n, a, b, k;
char s[N]; LL q_pow(LL a, LL b) {
LL ans = ;
while(b) {
if(b & ) ans = ans * a % mod;
a = a * a % mod; b >>= ;
}
return ans;
} LL ivn(LL x) {
return q_pow(x, mod - );
} int main() { scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
scanf("%s", s);
LL w = q_pow(b, k) * ivn(q_pow(a, k)) % mod;
w = (w + mod) % mod; LL ans = ;
LL cnt = (n + ) / k; for(LL i = ; i < k; i++) {
LL ret1 = q_pow(a, n - i) * q_pow(b, i) % mod;
LL ret2 = ( - q_pow(w, cnt) + mod) % mod;
LL ret3 = ivn(( - w + mod) % mod);
LL ret = (((ret1 * ret2) % mod) * ret3) % mod;
if(w == ) ret = (ret1 * cnt) % mod;
if(s[i] == '-') ret = -ret;
ans = (ans + ret + mod) % mod;
}
printf("%lld\n", ans);
return ;
}
/*
*/

Codeforces Round #475 (Div. 2) C - Alternating Sum的更多相关文章

  1. Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)

    Problem  Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...

  2. Codeforces Round #475 Div. 2 A B C D

    A - Splits 题意 将一个正整数拆分成若干个正整数的和,从大到小排下来,与第一个数字相同的数字的个数为这个拆分的权重. 问\(n\)的所有拆分的不同权重可能个数. 思路 全拆成1,然后每次将2 ...

  3. Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 2)

    A. Splits time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  4. Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 1)

    A. Alternating Sum 就是个等比数列,特判公比为 $1$ 的情况即可. #include <bits/stdc++.h> using namespace std; ; ; ...

  5. Codeforces Round #200 (Div. 1) B. Alternating Current 栈

    B. Alternating Current Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...

  6. Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp

    B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...

  7. Codeforces Round #344 (Div. 2) E. Product Sum 维护凸壳

    E. Product Sum 题目连接: http://www.codeforces.com/contest/631/problem/E Description Blake is the boss o ...

  8. Codeforces Round #200 (Div. 2)D. Alternating Current (堆栈)

    D. Alternating Current time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. Codeforces Round #238 (Div. 2) D. Toy Sum(想法题)

     传送门 Description Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to s ...

随机推荐

  1. MT【196】整数个数

    设函数$f(x)=x^2-2ax+15-2a$的两个零点分别为$x_1,x_2$, 且在区间$(x_1,x_2)$上恰好有两个正整数,则实数$a$的取值范围______ 提示:$1<|x_1-x ...

  2. bzoj 4631: 踩气球 线段树合并

    4631: 踩气球 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 265  Solved: 136[Submit][Status][Discuss] ...

  3. 德国GG了

    我想起了今年ZJOI 这就是生活啊,伤悲总是要面对的

  4. python之旅:面向对象进阶

    一 isinstance(obj,cls)和issubclass(sub,super) isinstance(obj,cls)检查是否obj是否是类 cls 的对象 class Foo(object) ...

  5. linux command ------ netstat

    netstat命令是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表.实际的网络连接以及每一个网络接口设备的状态信息. 语法选项 netstat [选项] -a或--all:显示所有连线中的 ...

  6. RabbitMQ的安装部署

    RabbitMQ安装部署 一.软件准备 wget http://erlang.org/download/otp_src_19.3.tar.gz wget http://www.rabbitmq.com ...

  7. angularJs的继承

    为什么要继承,本来是后端的概念,但是同样适用于前端开发.继承,无疑是将通用的东西抽取出来. 下面介绍的是angular的伪继承,就是说是通过继承scope这个变量来实现的.代码很简单,一行代码就可以. ...

  8. node.js通过edge访问.net动态链接库

    从了解node.js到现在经历了几个月时间,一直忙于实际的项目,没有动手写点关于node.js的代码.最近将开发工作安排就绪,个人的时间相对从容了,所以这几天开始测试一下node.js. 多年来,一直 ...

  9. Codeforces 314 E. Sereja and Squares

    http://codeforces.com/contest/314/problem/E 题意: 原本有一个合法的括号序列 擦去了所有的右括号和部分左括号 问有多少种填括号的方式使他仍然是合法的括号序列 ...

  10. [iOS问题归总]iPhone上传项目遇到的问题

    1. 在上传项目的时候,UpLoad App Store后弹出iTunes Store operation failed. 错误原因:你在ItunesConnect(https://itunescon ...