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 ...
随机推荐
- MT【100】经典计数之分配问题
注意:此讲适合联赛一试学生,以及参加清华北大等名校的自主招生的学生. 经典计数之分配问题:把n个球放进k个盒子.考虑分配方法有三类:1.无限制 2.每个盒子至多一个(f 单的)3.每个盒子至少一个(f ...
- BZOJ 4004: [JLOI2015]装备购买
4004: [JLOI2015]装备购买 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 1154 Solved: 376[Submit][Statu ...
- Graham's Scan法求解凸包问题
概念 凸包(Convex Hull)是一个计算几何(图形学)中的概念.用不严谨的话来讲,给定二维平面上的点集,凸包就是将最外层的点连接起来构成的凸多边型,它能包含点集中所有点的.严谨的定义和相关概念参 ...
- 洛谷 P3975 [TJOI2015]弦论 解题报告
P3975 [TJOI2015]弦论 题目描述 为了提高智商,ZJY开始学习弦论.这一天,她在<String theory>中看到了这样一道问题:对于一个给定的长度为\(n\)的字符串,求 ...
- [JSOI2007]文本生成器(AC自动机,DP)
题目链接: 洛谷 LOJ BZOJ 题目大意:给定 $n$ 个只含大写字母的串(称为可读串),问有多少种只含大写字母的长为 $m$ 的串,包含至少一个可读串. $1\le n\le 60,1\le \ ...
- Linux上vi编辑文件非正常退出后文件恢复
Vim另存文件的命令为 编辑完文件后Esc,输入以下指令 :w filename 编辑文件时非正常退出,会生成.hello.txt.swp的文件,还有一些其他信息 恢复文件要使用以下命令: [keys ...
- 数据量越发庞大怎么办?新一代数据处理利器Greenplum来助攻
作者:李树桓 个推数据研发工程师 前言:近年来,互联网的快速发展积累了海量大数据,而在这些大数据的处理上,不同技术栈所具备的性能也有所不同,如何快速有效地处理这些庞大的数据仓,成为很多运营者为之苦恼的 ...
- 使用 Nginx 和 Gunicorn 部署 Django 博客(转)
原文:http://zmrenwu.com/post/20/ http://www.siar.me/post/9/ 针对很多朋友反映按照教程的做法始终只能看到 Nginx 欢迎页面的问题,Tian ...
- Vue实例的生命周期(钩子函数)
Vue实例的生命钩子总共有10个 先上官方图: 下面时一个vue实例定义钩子函数的例子: var app=new Vue({ el:'#app', beforeCreate:function(){ c ...
- 网络技术之TCP三次握手
在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手方式建立一个连接 第一次握手:c->s 建立连接时,客户端发送SYN包(syn=j){注:syn:Synchronize Sequ ...