HDU 6050 17多校2 Funny Function(数学+乘法逆元)

For given integers N and M,calculate Fm,1 modulo 1e9+7.
The next T lines,each line includes two integers N and M .
1<=T<=10000,1<=N,M<2^63.
数学题,反正我不会。。。数学基础太差了,直接用大佬的数学公式写的
参考博客:http://www.cnblogs.com/Just--Do--It/p/7248089.html
主要是学到了取余和除的话需要求逆元!!可以用费马小定理求,目前我只会这个
继续加油!

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string.h>
#include<cmath>
#include<math.h>
using namespace std; #define MOD 1000000000+7 long long quick_mod(long long a,long long b)//快速幂,复杂度log2n
{
long long ans=;
while(b)
{
if(b&)
{
ans*=a;
ans%=MOD;
b--;
}
b/=;
a*=a;
a%=MOD;
}
return ans;
} long long inv(long long x)
{
return quick_mod(x,MOD-);//根据费马小定理求逆元,3*(3^(mod-2))=1
} int main()
{
int T;
scanf("%d",&T);
long long n,m,ans;
while(T--)
{
scanf("%lld%lld",&n,&m);
if(n%==)
ans=(quick_mod(quick_mod(,n)-,m-)*)*inv();
else
ans=(quick_mod(quick_mod(,n)-,m-)*+)*inv();
ans%=MOD;
printf("%lld\n",ans);
}
return true;
}
HDU 6050 17多校2 Funny Function(数学+乘法逆元)的更多相关文章
- HDU 6038 17多校1 Function(找循环节/环)
Problem Description You are given a permutation a from 0 to n−1 and a permutation b from 0 to m−1. D ...
- HDU 6140 17多校8 Hybrid Crystals(思维题)
题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...
- HDU 6143 17多校8 Killer Names(组合数学)
题目传送:Killer Names Problem Description > Galen Marek, codenamed Starkiller, was a male Human appre ...
- HDU 6045 17多校2 Is Derek lying?
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6045 Time Limit: 3000/1000 MS (Java/Others) Memory ...
- HDU 6124 17多校7 Euler theorem(简单思维题)
Problem Description HazelFan is given two positive integers a,b, and he wants to calculate amodb. Bu ...
- HDU 3130 17多校7 Kolakoski(思维简单)
Problem Description This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……. This seq ...
- HDU 6034 17多校1 Balala Power!(思维 排序)
Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He want ...
- HDU 6103 17多校6 Kirinriki(双指针维护)
Problem Description We define the distance of two strings A and B with same length n isdisA,B=∑i=0n− ...
- HDU 6098 17多校6 Inversion(思维+优化)
Problem Description Give an array A, the index starts from 1.Now we want to know Bi=maxi∤jAj , i≥2. ...
随机推荐
- PReLU
PReLU全名Parametric Rectified Linear Unit. PReLU-nets在ImageNet 2012分类数据集top-5上取得了4.94%的错误率,首次超越了人工分类的错 ...
- zk 创建瞬时、顺序节点的原理
命令: create -s -e /worker/lock xx zk 的实现代码在:PrepRequestProcessor.pRequest2Txn 中 //The number of chang ...
- 使用Swagger2构建强大的RESTful API文档(2)(二十三)
添加文档内容 在完成了上述配置后,其实已经可以生产文档内容,但是这样的文档主要针对请求本身,而描述主要来源于函数等命名产生,对用户并不友好,我们通常需要自己增加一些说明来丰富文档内容.如下所示,我们通 ...
- Struts初步入门(四)
1.默认Action-深入Struts struts.xml 文件: <struts> <package name="default" namespace=&qu ...
- vs 编译库文件 Qt编译库文件
QT 库能不能用 需要关注是minGW 还是MSVC编译的 Qt MinGW与MSVC对比 转:https://blog.csdn.net/u013185164/article/details/48 ...
- centos7.0 64位系统 安装PHP5.3 支持 nginx
1 安装PHP所需要的扩展 yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel curl cur ...
- 关于执行findbugs,checkstyle,jacoco插件检测代码,GitHook的脚本编写
Git钩子的作用: (pre-commit ) 在用户执行 git commit -m "xxx" 命令之前,先执行pre-commit文件中的脚本命令 在pre-commit文件 ...
- Mysql中contact、group_concat、concat_ws、repeat
一.CONCAT(str1,str2,…) 返回结果为连接参数产生的字符串.如有任何一个参数为NULL ,则返回值为 NULL. mysql> select concat('11','22',' ...
- Driver 01 进程隐藏
大二时候的代码以及笔记,当时暂时记录在QQ上在,现在发出来分享一下. 为了写驱动装一大堆的软件插件啥的,还常常失败. 这里就顺带总结下SDK下载和WinDbg symbol路径设置正确WinDbg却总 ...
- table添加行
需求是要实现表格的动态增加与删除,并且保留标题行和首行,找了半天jq插件,没找到合适的,所以自己写了个demo <!DOCTYPE html> <html> <head& ...