https://codeforces.com/problemset/problem/327/C

因为答案可以有前导零,所以0和5一视同仁。每个小节内,以排在第 $i$ 个的5为结尾的序列即为在前面 $0\thicksim i-1$ 共i个里面选 $0$ 、 $1$ 、 $2$ 直到 $i-1$ 个去除,由二项式定理知道这里是 $2^i$ 。

因为小节可以循环,每次循环后面的对应位置要多 $n$ 个元素可以去除,那么就多乘一个 $2^n$ ,而一共有 $k$ 节,由等比数列求和 $\frac{a_1(1-q^n)}{1-q}$ 得知其实就是 $\frac{2^{nk}-1}{2^n-1}$ 。

那么2的任意次方可以由快速幂求出来。除法可以用费马小定理求出来乘法逆元(这里的模数是质数,而不仅仅是与2的幂次互质)。(逆元为所求数的p-2次方)。

#include<bits/stdc++.h>
using namespace std;
#define ll long long ll p=;
ll qpow(ll x,ll n){
ll res=;
while(n){
if(n&)
res=res*x%p;
x=x*x%p;
n>>=;
}
return res;
} char a[];
ll k;
int main(){
scanf("%s",a);
scanf("%lld",&k);
ll n=strlen(a); ll cur=;
for(int i=;i<n;i++){
if(a[i]==''||a[i]==''){
cur+=qpow(,i);
cur%=p;
}
} ll ans=cur*(qpow(,n*k)-)%p*(qpow(qpow(,n)-,p-))%p;
printf("%lld\n",ans);
}

(水题)Codeforces - 327C - Magic Five的更多相关文章

  1. 水题 Codeforces Round #302 (Div. 2) A Set of Strings

    题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...

  2. 水题 Codeforces Round #300 A Cutting Banner

    题目传送门 /* 水题:一开始看错题意,以为是任意切割,DFS来做:结果只是在中间切出一段来 判断是否余下的是 "CODEFORCES" :) */ #include <cs ...

  3. 水题 Codeforces Round #299 (Div. 2) A. Tavas and Nafas

    题目传送门 /* 很简单的水题,晚上累了,刷刷水题开心一下:) */ #include <bits/stdc++.h> using namespace std; ][] = {" ...

  4. 水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas

    题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm ...

  5. 水题 Codeforces Round #303 (Div. 2) A. Toy Cars

    题目传送门 /* 题意:5种情况对应对应第i或j辆车翻了没 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 3: if both cars turned over during th ...

  6. 水题 Codeforces Round #286 (Div. 2) A Mr. Kitayuta's Gift

    题目传送门 /* 水题:vector容器实现插入操作,暴力进行判断是否为回文串 */ #include <cstdio> #include <iostream> #includ ...

  7. 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root

    题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...

  8. 水题 Codeforces Round #306 (Div. 2) A. Two Substrings

    题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...

  9. 水题 Codeforces Round #308 (Div. 2) A. Vanya and Table

    题目传送门 /* 水题:读懂题目就能做 */ #include <cstdio> #include <iostream> #include <algorithm> ...

  10. 水题 Codeforces Round #307 (Div. 2) A. GukiZ and Contest

    题目传送门 /* 水题:开个结构体,rk记录排名,相同的值有相同的排名 */ #include <cstdio> #include <cstring> #include < ...

随机推荐

  1. nexus批量更新jar包

    nexus批量更新jar包 学习了:https://blog.csdn.net/newtelcom/article/details/54379607 手动进行jar包的拷贝,在维护界面内进行批量更新:

  2. win7下 安装 source code pro

    转: http://my.oschina.net/yearnfar/blog/325107 source code pro 字体安装, 一. 去 https://github.com/adobe-fo ...

  3. nextSibling和previousSibling

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  4. 《STL源代码剖析》---stl_deque.h阅读笔记(2)

    看完,<STL源代码剖析>---stl_deque.h阅读笔记(1)后.再看代码: G++ 2.91.57,cygnus\cygwin-b20\include\g++\stl_deque. ...

  5. HDU 6183 Color it cdq分治 + 线段树 + 状态压缩

    Color it Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Pro ...

  6. Linux系统(Centos)下安装Java环境配置步骤详述

    1.首先要去下载好JDK,Java SE 8的官方网址是http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2 ...

  7. rails find find_by where

    find根据id进行查询,像Product.find(3),查询语句是Product Load (0.1ms) SELECT "products".* FROM "pro ...

  8. redis.Pool 配置

    http://blog.csdn.net/xiaohu50/article/details/51606349

  9. HDU2732 Leapin' Lizards —— 最大流、拆点

    题目链接:https://vjudge.net/problem/HDU-2732 Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others)    M ...

  10. eclipse创建maven项目出现以下报错: org.apache.maven.archiver.MavenArchiver.getManifest (org.apache.maven.project.MavenProject,org.apache.mav en.archiver.MavenArchiveConfiguration)

    解决方法: 更新eclipse中的maven插件 Help ->  Install New Software -> add ->  http://repo1.maven.org/ma ...