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

 #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. 做前端好还是Java好?

    做前端好还是Java好?看这三方面 转载 2017年11月14日 00:00:00 1047这几年来伴随着互联网的迅速发展,新兴互联网产业的兴起,传统行业也逐渐开始互联网化,使得互联网职业在这样的背景 ...

  2. 【bzoj3160】 万径人踪灭

    http://www.lydsy.com/JudgeOnline/problem.php?id=3160 (题目链接) 题意 给定一个由'a'和'b'构成的字符串,求不连续回文子序列的个数. Solu ...

  3. 【模板】LCA

    代码如下 #include <bits/stdc++.h> using namespace std; const int maxn=5e5+10; inline int read(){ i ...

  4. SQL Server 行列相互转换命令:PIVOT和UNPIVOT使用详解

    一.使用PIVOT和UNPIVOT命令的SQL Server版本要求 1.数据库的最低版本要求为SQL Server 2005 或更高. 2.必须将数据库的兼容级别设置为90 或更高. 3.查看我的数 ...

  5. 「Vue」vue cli3项目打包为APP方法及坑点

    1.执行npm run build之后生成dist文件夹 2.打开HBuilderX新建一个APP项目 3.把dist文件夹里的所有文件拷贝替换到APP文件夹下 4.打开manifest.json文件 ...

  6. Python3.x文件处理详解

    Python3.x文件处理详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 任何一门语言都有其特有的操作文件的方式,Python2.x版本有两种操作文件的方式,没错就是open函 ...

  7. DataGridView刷新数据

    在DataGridView上操作数据之后,无论是增删改都是对数据库进行了操作,而DataGridView这个控件在操作之后是不会变化的,需要重新的去数据库里读取一下数据才行,可以理解为之刷新 Data ...

  8. TradingView学习记录

    官网:https://cn.tradingview.com   申请图表库 用本地服务器打开 二:文件目录 三:基础概念 3.1 UDF:通用数据饲料(Universal Data Feed)     ...

  9. ajax实现输入用户名异步提示是否可用

    <script type="text/javascript"> //页面加载完毕后执行 $(document).ready(function(){ //用户名输入框绑定 ...

  10. 网络编程之tcp窗口滑动以及拥塞控制

    TCP协议作为一个可靠的面向流的传输协议,其可靠性和流量控制由滑动窗口协议保证,而拥塞控制则由控制窗口结合一系列的控制算法实现.一.滑动窗口协议     关于这部分自己不晓得怎么叙述才好,因为理解的部 ...