(快速幂)Key Set--hdu--5363
链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5363
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86698#problem/C


代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std; #define mod 1000000007 long long Pow(long long a, long long b)
{
if(b==)
return a%mod; long long d=Pow(a, b/); if(b%)
return d * d * a %mod;
else
return d * d % mod;
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
long long n;
scanf("%lld", &n); if(n==)
{
printf("0\n");
continue;
} long long ans = Pow(, n-); printf("%lld\n", ans-);
}
return ;
}
代码2:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std; #define mod 1000000007 __int64 Pow(int a,int b)
{
__int64 r=,base=a;
while(b)
{
if(b&)
r=(r*base)%mod;
base=(base*base)%mod;
b>>=;
}
return r%mod;
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
long long n;
scanf("%lld", &n); if(n==)
{
printf("0\n");
continue;
} long long ans = Pow(, n-); printf("%lld\n", ans-);
}
return ;
}
T3CGPPZS.png)
(快速幂)Key Set--hdu--5363的更多相关文章
- 一些特殊的矩阵快速幂 hdu5950 hdu3369 hdu 3483
思想启发来自, 罗博士的根据递推公式构造系数矩阵用于快速幂 对于矩阵乘法和矩阵快速幂就不多重复了,网上很多博客都有讲解.主要来学习一下系数矩阵的构造 一开始,最一般的矩阵快速幂,要斐波那契数列Fn=F ...
- Key Set HDU - 5363
这个题目套公式 2^(n-1)-1,再来个快速幂基本上就可以AC了 写这个题目的: 公式容易推到错: 容易写成 2^n-1/2...这样写出来结果也不错 但是一直哇 AC: #include< ...
- 矩阵快速幂AC代码HDU 2035
#include <iostream> using namespace std;const int MOD = 1000;//像这样的一个常量就应该专门定义一下 int PowMod(in ...
- HDU 1061 Rightmost Digit --- 快速幂取模
HDU 1061 题目大意:给定数字n(1<=n<=1,000,000,000),求n^n%10的结果 解题思路:首先n可以很大,直接累积n^n再求模肯定是不可取的, 因为会超出数据范围, ...
- hdu 5363 组合数学 快速幂
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Problem Descrip ...
- HDU 5895 Mathematician QSC(矩阵乘法+循环节降幂+除法取模小技巧+快速幂)
传送门:HDU 5895 Mathematician QSC 这是一篇很好的题解,我想讲的他基本都讲了http://blog.csdn.net/queuelovestack/article/detai ...
- HDU 2855 斐波那契+矩阵快速幂
http://acm.hdu.edu.cn/showproblem.php?pid=2855 化简这个公式,多写出几组就会发现规律 d[n]=F[2*n] 后面的任务就是矩阵快速幂拍一个斐波那契模板出 ...
- HDU 2855 (矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2855 题目大意:求$S(n)=\sum_{k=0}^{n}C_{n}^{k}Fibonacci(k)$ ...
- HDU 2842 (递推+矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2842 题目大意:棒子上套环.第i个环能拿下的条件是:第i-1个环在棒子上,前i-2个环不在棒子上.每个 ...
- HDU 4471 矩阵快速幂 Homework
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4471 解题思路,矩阵快速幂····特殊点特殊处理····· 令h为计算某个数最多须知前h个数,于是写 ...
随机推荐
- 将*.sql数据库脚本导入到sqlserver中(sql文件导入sqlserver)
在SqlServer中这个是用生成sql脚本生成的 要是在导入数据库用数据导入/导出向导导不进去 其实要用查询分析器来打开sql文件 然后执行就可以了
- Haskell语言学习笔记(28)Data.Map
Map Prelude> import Data.Map as Map Prelude Map> :set -XOverloadedLists Prelude Map> Overlo ...
- windows本地blast
详细可参考https://www.jianshu.com/p/2f125cdf8262:https://blog.csdn.net/qq_34296043/article/details/544277 ...
- golang 打印变量类型
fmt.Println("type:", reflect.TypeOf(err.Error()))
- socket.io api 总结
server 端const io = require('socket.io')(8000, { // path: '/socket', pingInterval: 10000, pingTimeout ...
- PAT L3-008 喊山(广搜)
喊山,是人双手围在嘴边成喇叭状,对着远方高山发出“喂—喂喂—喂喂喂……”的呼唤.呼唤声通过空气的传递,回荡于深谷之间,传送到人们耳中,发出约定俗成的“讯号”,达到声讯传递交流的目的.原来它是彝族先民用 ...
- jquery 赋值时不触发change事件解决
$("#optionsId").change(function(){ $("#selectOptionsText").val('测试'); }); $(&quo ...
- 在探http请求
参考:https://itbilu.com/other/relate/Ny2IWC3N-.html Cookie和Session都是为了解决HTTP协议的无状态问题,存储HTTP通讯中客户端与服务器之 ...
- 子类覆写的变量被private隐藏,强制转换方式通过子类访问父类的被覆写变量:
import static java.lang.System.*; public class SuperParent{ public static void main(String[] args){ ...
- 品味性能之道<四>:管理重于技术
一.性能优化中的角色分工 (1).老外的角色分工 在oracle性能优化方法论中,将IT系统中不同角色需要承担的性能优化工作罗列如下. 各司其职的角色分工 业务分析人员 1.业务需 ...