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

  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. #define fi first
  4. #define se second
  5. #define mk make_pair
  6. #define pii pair<int,int>
  7. #define ull unsigned long long
  8. using namespace std;
  9.  
  10. const int N=1e6+;
  11. const int M=+;
  12. const int inf=0x3f3f3f3f;
  13. const LL INF=0x3f3f3f3f3f3f3f3f;
  14. const int mod=1e9 + ;
  15.  
  16. LL n, a, b, k;
  17. char s[N];
  18.  
  19. LL q_pow(LL a, LL b) {
  20. LL ans = ;
  21. while(b) {
  22. if(b & ) ans = ans * a % mod;
  23. a = a * a % mod; b >>= ;
  24. }
  25. return ans;
  26. }
  27.  
  28. LL ivn(LL x) {
  29. return q_pow(x, mod - );
  30. }
  31.  
  32. int main() {
  33.  
  34. scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
  35. scanf("%s", s);
  36. LL w = q_pow(b, k) * ivn(q_pow(a, k)) % mod;
  37. w = (w + mod) % mod;
  38.  
  39. LL ans = ;
  40. LL cnt = (n + ) / k;
  41.  
  42. for(LL i = ; i < k; i++) {
  43. LL ret1 = q_pow(a, n - i) * q_pow(b, i) % mod;
  44. LL ret2 = ( - q_pow(w, cnt) + mod) % mod;
  45. LL ret3 = ivn(( - w + mod) % mod);
  46. LL ret = (((ret1 * ret2) % mod) * ret3) % mod;
  47. if(w == ) ret = (ret1 * cnt) % mod;
  48. if(s[i] == '-') ret = -ret;
  49. ans = (ans + ret + mod) % mod;
  50. }
  51. printf("%lld\n", ans);
  52. return ;
  53. }
  54. /*
  55. */

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【100】经典计数之分配问题

    注意:此讲适合联赛一试学生,以及参加清华北大等名校的自主招生的学生. 经典计数之分配问题:把n个球放进k个盒子.考虑分配方法有三类:1.无限制 2.每个盒子至多一个(f 单的)3.每个盒子至少一个(f ...

  2. BZOJ 4004: [JLOI2015]装备购买

    4004: [JLOI2015]装备购买 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 1154  Solved: 376[Submit][Statu ...

  3. Graham's Scan法求解凸包问题

    概念 凸包(Convex Hull)是一个计算几何(图形学)中的概念.用不严谨的话来讲,给定二维平面上的点集,凸包就是将最外层的点连接起来构成的凸多边型,它能包含点集中所有点的.严谨的定义和相关概念参 ...

  4. 洛谷 P3975 [TJOI2015]弦论 解题报告

    P3975 [TJOI2015]弦论 题目描述 为了提高智商,ZJY开始学习弦论.这一天,她在<String theory>中看到了这样一道问题:对于一个给定的长度为\(n\)的字符串,求 ...

  5. [JSOI2007]文本生成器(AC自动机,DP)

    题目链接: 洛谷 LOJ BZOJ 题目大意:给定 $n$ 个只含大写字母的串(称为可读串),问有多少种只含大写字母的长为 $m$ 的串,包含至少一个可读串. $1\le n\le 60,1\le \ ...

  6. Linux上vi编辑文件非正常退出后文件恢复

    Vim另存文件的命令为 编辑完文件后Esc,输入以下指令 :w filename 编辑文件时非正常退出,会生成.hello.txt.swp的文件,还有一些其他信息 恢复文件要使用以下命令: [keys ...

  7. 数据量越发庞大怎么办?新一代数据处理利器Greenplum来助攻

    作者:李树桓 个推数据研发工程师 前言:近年来,互联网的快速发展积累了海量大数据,而在这些大数据的处理上,不同技术栈所具备的性能也有所不同,如何快速有效地处理这些庞大的数据仓,成为很多运营者为之苦恼的 ...

  8. 使用 Nginx 和 Gunicorn 部署 Django 博客(转)

    原文:http://zmrenwu.com/post/20/  http://www.siar.me/post/9/ 针对很多朋友反映按照教程的做法始终只能看到 Nginx 欢迎页面的问题,Tian ...

  9. Vue实例的生命周期(钩子函数)

    Vue实例的生命钩子总共有10个 先上官方图: 下面时一个vue实例定义钩子函数的例子: var app=new Vue({ el:'#app', beforeCreate:function(){ c ...

  10. 网络技术之TCP三次握手

    在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手方式建立一个连接 第一次握手:c->s 建立连接时,客户端发送SYN包(syn=j){注:syn:Synchronize Sequ ...