Codeforces Round #475 (Div. 2) C - Alternating Sum
等比数列求和一定要分类讨论!!!!!!!!!!!!
#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的更多相关文章
- Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)
Problem Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...
- Codeforces Round #475 Div. 2 A B C D
A - Splits 题意 将一个正整数拆分成若干个正整数的和,从大到小排下来,与第一个数字相同的数字的个数为这个拆分的权重. 问\(n\)的所有拆分的不同权重可能个数. 思路 全拆成1,然后每次将2 ...
- 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 ...
- Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 1)
A. Alternating Sum 就是个等比数列,特判公比为 $1$ 的情况即可. #include <bits/stdc++.h> using namespace std; ; ; ...
- Codeforces Round #200 (Div. 1) B. Alternating Current 栈
B. Alternating Current Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...
- 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/ ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- winform程序关闭界面时弹出提示框
void Form1_FormClosing(object sender, FormClosingEventArgs e){ if (MessageBox.Show( "窗口关闭后,数据即将 ...
- GO进程调度相关源码学习
启动流程 procresize流程 malloc.go Memory allocator sizeclass.go span按大小区分的 类型定义 mbitmap.go type and heap b ...
- Linux掉电处理
在嵌入式设备中,掉电处理一直是一项比较麻烦的工作,在具有Linux系统的设备中,系统的种种数据的处理更是增加掉电处理的难度.现在做以下几点总结,再遇到类似问题可以做个参考. 1,系统启动的处理 在系统 ...
- 一文掌握Docker Compose
目录 Docker Compose介绍 Docker Compose安装 Docker Compose基本示例 1.基本文件及目录设置 2.创建一个Dockerfile 3.通过docker-comp ...
- Zabbix应用六:Zabbix监控Redis
利用Zabbix监控Redis Zabbix监控redis就比较简单了,因为zabbix官方提供了监控redis的模版和脚本,而且脚本有nodejs和python两种,下载地址:https://git ...
- Zabbix应用五:Zabbix监控多Tomcat
利用Zabbix Trapper方式监控多Tomcat实例 Zabbix自带的模版(JMX Tomcat.JMX Generic)默认只能在一台机器上监控一个tomcat实例(因为监控项中的key不能 ...
- iperf测试网络带宽
http://blog.chinaaet.com/telantan/p/30901 https://boke.wsfnk.com/archives/288.html https://www.ibm.c ...
- 如何把手机app的视频下载到手机上?网页上的视频怎么下载?
手机上小视频怎么下载?求推荐不需要安装软件的下载方法? 如何把手机app的视频下载到手机上?比如把快手上的视频下载到手机上? 如何免费下载视频? ... 答案当然是用iiiLab提供的在线视频解析下载 ...
- Java 在匿名内部函数中为外部函数变量赋值的解决方案
Java匿名内部函数本人不怎么主动使用,但是经常会调用一些API,其中会调用一些接口,而这些接口是需要使用匿名内部类来实现的,于是就遇到了一些问题. 就比如okHttp3 的接口调用 OkHttpCl ...
- bzoj千题计划209:bzoj1185: [HNOI2007]最小矩形覆盖
http://www.lydsy.com/JudgeOnline/problem.php?id=1185 题解去看它 http://www.cnblogs.com/TheRoadToTheGold/p ...