(快速幂)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个数,于是写 ...
随机推荐
- Session保存数据
int nameid=dao.isLegalUser(name, password);/ /方法返回int数据 request.setAttribute("nam ...
- [故障引起的故事]URL中带加号的处理
问题起因: 客户订购了一关键字为"e+h 变送器" , 在首页推荐广告中,会根据用户在search 搜索过的关键字进行一个匹配投放.技术实现是UED 通过JS 获取coo ...
- winform程序开机启动时的运行目录
并不是程序的当前路径,而是系统的某个目录 如环境是win10 64位,路径是 c:\winfows\SysWOW64\ConfigInfor.json
- smartos介绍
https://wiki.smartos.org A Little History 2005年,Sun Microsystems开源了其著名的Unix操作系统Solaris,最终被发布为一个名为Ope ...
- Ansible Playbook 循环
Standard Loops 为了节省一些打字,重复的任务可以写成如下: - name: add several users user: name: "{{ item }}" st ...
- 利用R产生随机数
生成随机数有两个函数runif()和rnorm(),其中r表示的是random随机的意思,unif表示的是均匀分布,而norm表示的是正态分布. 1)生成10个2到3之间的,服从均匀分布的随机数:ru ...
- RedisTemplate Redis 操作
stringRedisTemplate.opsForValue().set("test", "100",60*10,TimeUnit.SECONDS);//向r ...
- OpenOffice Word文档转换成Html格式
为什么会想起来将上传的word文档转换成html格式呢?设想,如果一个系统需要发布在页面的文章都是来自word文档,一般会执行下面的流程:使用word打开文档,Ctrl+A,进入发布文章页面,Ctrl ...
- Unicode、UTF8与UTF16
1 概念 Unicode是国际组织制定的可以容纳世界上所有文字和符号的字符编码方案 UTF是“Unicode Transformation Format”的缩写,可以翻译成Unicode字符集转换格式 ...
- Windows XP with SP3大客户免激活日文版
原贴地址:http://www.humin.com.cn/ja_windows_xp_professional_with_service_pack_3_x86_dvd_vl_x14-74058-iso ...