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

 #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. 【转】vi 写完文件保存时才发现是 readonly

    在MAC上编辑apache配置文件,老是忘记sudo…… readonly的文件保存时提示 add ! to override, 但这仅是对root来说的啊! 百毒了一下竟然还有解决方案!! :w ! ...

  2. 洛谷 P2527 [SHOI2001]Panda的烦恼 解题报告

    P2527 [SHOI2001]Panda的烦恼 题目描述 panda是个数学怪人,他非常喜欢研究跟别人相反的事情.最近他正在研究筛法,众所周知,对一个范围内的整数,经过筛法处理以后,剩下的全部都是质 ...

  3. svn:重命名文件之后,不允许提交

    1.错误代码 org.apache.subversion.javahl.ClientException: Illegal target for the requested operation svn: ...

  4. es6 export 和 export default区别

    相信很多人都使用过export.export default.import,然而它们到底有什么区别呢? 在JavaScript ES6中,export与export default均可用于导出常量.函 ...

  5. 样本标准差分母为何是n-1

    sklearn实战-乳腺癌细胞数据挖掘 https://study.163.com/course/introduction.htm?courseId=1005269003&utm_campai ...

  6. Java基础-逻辑运算符Logic Operators

    Java基础-逻辑运算符Logic Operators 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.逻辑运算符 逻辑运算符是对布尔值进行操作运算的,常见的有: 1>.逻 ...

  7. 在“安装”阶段发生异常。 System.Security.SecurityException: 未找到源,但未能

    写Windows服务的时候,运行了一下,就是没反应,命令框一闪而过,查了一下异常,大致是题目的那样.原因是因为权限不足.但是在网上搜的方法都不顶用. 解决方法如下: (1)以管理员身份运行CMD: ( ...

  8. [六字真言]2.嘛.异常定制和通用.md

    幻世当空 恩怨休怀 舍悟离迷 六尘不改 且怒且悲且狂哉! 最近一直在循环的一首歌! 丰富自己,比取悦他人更有力量.种下梧桐树,引得凤凰来.你若盛开,蝴蝶自来! 言归正传! 言归正传! 不要去大包大揽 ...

  9. jinja模板语言

    模板 要了解jinja2,那么需要先理解模板的概念.模板在Python的web开发中广泛使用,它能够有效的将业务逻辑和页面逻辑分开,使代码可读性增强.并且更加容易理解和维护. 模板简单来说就是一个其中 ...

  10. js星星评分插件

    下载:https://files.cnblogs.com/files/wordblog/%E6%98%9F%E6%98%9F%E6%8F%92%E4%BB%B6.rar