题目链接:传送门

思路:

考虑每一列有2种颜色,总共有n行,每一行的第一个格确定颜色,由于左右颜色不相同,后面的行就确定了。

所以总共有2^n中结果。

由于n太大,所以要用到费马小定理a^n%mod=a^(n%(mod-1))%mod,所以先求出a的指数,然后用快速幂求解就好了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
typedef long long LL;
const LL MOD = 1e9+;
const int maxn = ;
char str1[maxn],str2[maxn];
int main(void)
{
int i,j;
LL ans=,n,res=,tp=;
scanf("%s%s",str1,str2);
n=strlen(str1);
for(i=;i<n;i++) ans=(ans*+str1[i]-'')%(MOD-);
n=ans;
while(n){
if(n&) res=res*tp%MOD;
tp=tp*tp%MOD;
n>>=;
}
printf("%lld\n",res);
return ;
}

牛客训练四:Applese 涂颜色(费马小定理+快速幂)的更多相关文章

  1. BZOJ_[HNOI2008]_Cards_(置换+Burnside引理+乘法逆元+费马小定理+快速幂)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1004 共n个卡片,染成r,b,g三种颜色,每种颜色的个数有规定.给出一些置换,可以由置换得到的 ...

  2. hdu-5667 Sequence(矩阵快速幂+费马小定理+快速幂)

    题目链接: Sequence Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) ...

  3. 数论 --- 费马小定理 + 快速幂 HDU 4704 Sum

    Sum Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=4704 Mean: 给定一个大整数N,求1到N中每个数的因式分解个数的 ...

  4. 2014多校第一场 I 题 || HDU 4869 Turn the pokers(费马小定理+快速幂模)

    题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少 ...

  5. hdu_4869(费马小定理+快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4869 Turn the pokers Time Limit: 2000/1000 MS (Java/O ...

  6. hdu4549(费马小定理 + 快速幂)

    M斐波那契数列F[n]是一种整数数列,它的定义如下: F[0] = a F[1] = b F[n] = F[n-1] * F[n-2] ( n > 1 ) 现在给出a, b, n,你能求出F[n ...

  7. HDU 4704 Sum(隔板原理+组合数求和公式+费马小定理+快速幂)

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=4704 Problem Description   Sample Input 2 Sample Outp ...

  8. hdu1576-A/B-(同余定理+乘法逆元+费马小定理+快速幂)

    A/B Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  9. 【费马小定理+快速幂取模】ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies

    G. Give Candies There are N children in kindergarten. Miss Li bought them N candies. To make the pro ...

随机推荐

  1. Unity3d插件Master Audio AAA Sound v3.5

    Unity3d声音类插件Master Audio AAA Sound v3.5.8.3Master Audio gives you tremendous ease of use, speed, pow ...

  2. Codeforces Beta Round #22 (Div. 2 Only)

    Codeforces Beta Round #22 (Div. 2 Only) http://codeforces.com/contest/22 A 水题 #include<bits/stdc+ ...

  3. maven 常用参数使用详解

    前言 作为java开发按人员,使用maven构建似乎成为了工作中平常的事情,但有时会遇到一些问题,感到困惑,于是我整理出来,方便其他同学更好的使用,以后会慢慢更新这个文章. 命令介绍 -DskipTe ...

  4. Qt: 加入打印支持

    写记事本打印功能所遇问题,记录以便于查阅. 在vs系统中开发Qt,加入打印支持,不似在QtCreator之pro文件中中加QT +=printsupport解决. 而要在vs(以vs2015为例)中, ...

  5. 整合使用持久层框架mybatis 使用SqlSessionTemplate模板类与使用映射接口 对比

    spring中整合使用mybatis的用法总结 一:在Spring配置Mybatis 第一步:将mybatis-spring类包添加 到项目的类库中 第二步:编写spring和持久层衔接的xml文件, ...

  6. for all entries

    1.必须要判断for all entries in后面的内表是否为空,如果为空,where条件中与内表中字段进行比较的结果全部为真,会导致取出非常多的数据,影响系统性能.2.使用for all ent ...

  7. ABAP中不修改内表参照的结构,给内表/结构体增加字段

    Situation: DATA:       itab  TYPE STANDARD TABLE OF zsrsodtla_stru1,      wa_itab TYPE zsrsodtla_str ...

  8. webpack(一) 安装使用 之css使用注意

    在webpackDemo 文件夹中新建 style.css,index.html style.css 中将背景色设为红色. body{ background-color: red; } he'llWo ...

  9. 利用Java创建Windows服务

    1.Java测试代码 import org.apache.log4j.Logger; public class Test { private static Logger logger = Logger ...

  10. PHP统计网站pv(访问量)

    //首先判断有没有统计的文件 if(is_file("pv.txt")){//有 //取文件里面的值 $count=file_get_contents("pv.txt&q ...