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

  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. 【转】#pragma的用法

    在所有的预处理指令中,#Pragma 指令可能是最复杂的了,它的作用是设定编译器的状态或者是指示编译器完成一些特定的动作.#pragma指令对每个编译器给出了一个方法,在保持与C和C++语言完全兼容的 ...

  2. HDU 4280 Island Transport(网络流,最大流)

    HDU 4280 Island Transport(网络流,最大流) Description In the vast waters far far away, there are many islan ...

  3. 个推基于 Apache Pulsar 的优先级队列方案

    作者:个推平台研发工程师 祥子 一.业务背景在个推的推送场景中,消息队列在整个系统中占有非常重要的位置.当 APP 有推送需求的时候, 会向个推发送一条推送命令,接到推送需求后,我们会把APP要求推送 ...

  4. python数据分析scipy和matplotlib(三)

    Scipy 在numpy基础上增加了众多的数学.科学及工程常用的库函数: 线性代数.常微分方程求解.信号处理.图像处理.稀疏矩阵等: Matplotlib 用于创建出版质量图表的绘图工具库: 目的是为 ...

  5. Saltstack-API(十二)

    Saltstack-API 官方文档 https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.htm ...

  6. CSS3 定位| Position研究

    视区(视口) 当浏览者查看一份网页文件时,通常使用者代理(User Agents, UA, 浏览器)会提供给浏览者一个视区(视窗或者是画面里的其它可视区域).当我们调整视区大小时,UA 就有可能会改变 ...

  7. <td>内容超出自动换行

    td 内容自动换行 table表格td设置宽度后文字太多自动换行 设置table 的 style="table-layout:fixed;" 然后设置td的 style=" ...

  8. sql 跨服务器查询数据

    方法一:用OPENDATASOURCE [SQL SERVER] 跨服务器查询 --1 打开 reconfigure reconfigure SELECT * FROM OPENDATASOURCE( ...

  9. Javascript - Vue - 指令

    指令 v-cloak 解决闪烁,闪烁是指在网速较慢的情况下可能会出现插值表达式{{}}还没有填充数据时会把该表达式直接显示在页面上,如果不希望看到插值表达式则可以使用v-cloak指令,具体做法如下 ...

  10. 查询总结、HQL语法、QBC(QueryByCriteria)深入学习

    1.查询总结 在之前的批量查询练习的时候练习基本五种查询方法的使用: 1.OID查询---根据对象ID进行查询 2.对象属性导航查询: obj.getXXX 3.HQL查询:Query对象查询 4.Q ...