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. 配置resin支持maven项目

    1. 在resin.conf中找到 <!-- includes the app-default fordefault web-app behavior --> <resin:impo ...

  2. Effective C++ 条款七 为多态基类声明virtual析构函数

    class TimeKeeper { public: TimeKeeper(); // ~TimeKeeper(); 错误,此作为一个基类,被继承了.其继承类被delete后,基类被销毁,但继承类可能 ...

  3. 【Leetcode】经典的Jump Game in JAVA

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  4. ScaleYViewPager

    https://github.com/eltld/ScaleYViewPager

  5. Codeforces 558C Amr and Chemistry

    题意: n个数.每次能够选一个数 让其 *=2 或者 /=2 问至少操作多少次使得全部数相等. 思路: 对于每一个数,计算出这个数能够变成哪些数,以及变成那个数的最小步数,用两个数组保存 cnt[i] ...

  6. WCF服务端的.NET Core支持项目Core WCF 正式启动

    长期以来在wcf客户端库 https://github.com/dotnet/wcf 里反应最强烈的就是.NET Core的服务端支持 https://github.com/dotnet/wcf/is ...

  7. &lt;十二&gt;读&lt;&lt;大话设计模式&gt;&gt;之状态模式

    对于状态模式,<<大话设计模式>>是以人从上班到下班到加班的状态来展开讲述的.状态模式事实上就是某一个对象在某个过程或者时间的一个状态记录,可是这个状态的顺序不能发生变化.在程 ...

  8. html-基本form元素---ShinePans

    <html> <meta http-equiv="content-type" content="text/html;charset=UTF-8" ...

  9. debian iptables持久化

    1 保存iptables iptables-save > /etc/iptables.rules   2 创建启动文件 touch /etc/network/if-pre-up.d/iptabl ...

  10. quilt

    1 什么是quilt quilt是一个patch管理工具,特别适合于对多个patch进行管理. quilt是基于gnu patch和diff的. 2 使用quilt创建一个patch 第一步,quil ...