(快速幂)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个数,于是写 ...
随机推荐
- unity WWW加载进度条
using UnityEngine; using System.Collections; public class testProgress : MonoBehaviour { void Start ...
- Boost.Coroutine2:学习使用Coroutine(协程)
function(函数)routine(例程)coroutine (协程) 函数,例程以及协程都是指一系列的操作的集合. 函数(有返回值)以及例程(没有返回值)也被称作subroutine(子例程), ...
- 将Delphi的对象方法设为回调函数
心血来潮,为了实现更好的通用性和封装性,需要把类方法作为回调函数,搜得一篇好文,节选转发.命名似乎应该是MethodToCallback才合适,可惜调试时总是报错,debugging. 原文地址:ht ...
- 吴裕雄 python神经网络 水果图片识别(2)
import osimport numpy as npimport matplotlib.pyplot as pltfrom skimage import color,data,transform,i ...
- Windows驱动手动卸载与安装
彻底卸载的流程 1.删除C:\windows\inf\oem.inf路径下的所有oem文件 2.删除c:\windows\system32\drivers路径下对应的sys文件 3.(重要) 第一步: ...
- SQL查询效率where语句条件
有索引的列优先,都有索引的看查询出来的数据量,少的优先 in ,not in,<>,is null,is not null 等由于不会走索引,尽量不要使用. WHERE子句后面的条件顺序对 ...
- 等待时间,time.sleep()和implicitly_wait()
在运行一个以前执行的过的功能时,报错了,不能执行了. 功能描述:通过导航,选择下拉项(发布职位功能),下面是审查的元素: 获取元素的代码: 尝试了用xpath去获取:driver.find_eleme ...
- ubuntu16.04安装virtualbox
download:download.virtualbox.org/virtualbox/5.0.10/virtualbox-5.0_5.0.10-104061~Ubuntu~trusty_amd64. ...
- C函数指针的用法
1.最简单的用法: #include <cstdio> int (*p)(int);//定义一个函数指针变量p(下面的f其实是一个常量函数指针) int f(int x) { printf ...
- python单线程下实现多个socket并发
先看服务端的代码 import sys # import socket import time import gevent from gevent import socket from gevent ...