题目链接:传送门

思路:

考虑每一列有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. 微信小程序开发——获取小程序带参二维码全流程

    前言: 想要获取微信小程序带参数二维码,如这种: 官方文档只说了获取小程序码和二维码的三种接口及调用(参考链接:https://developers.weixin.qq.com/miniprogram ...

  2. 自动化测试之selenium工具简单介绍

    一.selenium简单介绍 1.selenium的成员 2.selenium工作原理 二.webdrive 常见元素定位

  3. 项目总结10:通过反射解决springboot环境下从redis取缓存进行转换时出现ClassCastException异常问题

    通过反射解决springboot环境下从redis取缓存进行转换时出现ClassCastException异常问题 关键字 springboot热部署  ClassCastException异常 反射 ...

  4. TableView中Label自适应高度

    //Xcode6.3以后label自适应需要添加两个属性 _tableView.rowHeight = UITableViewAutomaticDimension; //给予预计行高 _tableVi ...

  5. Head First Servlets & JSP 学习笔记 第二章 —— Web应用体系结构

    Servlet没有main()方法,所以Servlet受其他人控制,这个其他人就是容器!而Tomcat就是一种容器. 容器向Servlet提供Http请求和Http响应:容器来调用Servlet的do ...

  6. Faiss教程:索引(2)

    索引的I/O与复制 所有的函数都是深复制,我们不需要关心对象关系. I/O函数: write_index(index, "large.index"): 写索引到文件 Index * ...

  7. js封装插件

    js方式: (function(){ var demo = function(options){ this.options = $.extend({ "x" : "1&q ...

  8. .netcore webapi iis 虚拟目录下载apk文件

    首先贴上微软的文档:https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files 参考网址:http://www.cnb ...

  9. webpack接上一篇

    html-webpack-plugin 自动生成html文件 安装:npm install html-webpack-plugin --save-dev 使用 在webpack.config.js中引 ...

  10. encode/decode/bytes

    python3中如何将字符型转换成utf-8格式的bytes类型 str_me = '字符是我'.encode('utf-8') print(str_me) >>:b'\xe5\xad\x ...