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. ...
随机推荐
- codepen素材 coffeeScript -> JavaScript
将coffeeScript代码复制到下面的网址进行转换: http://js2.coffee/
- java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). at co ...
- OSS 实例
步骤 1.初始化ossClient实例 2.判断bucket是否存在(doesBucketExist) 3.上传图片(putObject(bucket,key,file))(注意:key是图片所在的路 ...
- ActiveMQ broker 集群, 静态发现和动态发现
下载 activemq 压缩包解压后,conf 目录下有各种示例配置文件,红线标出的是静态发现和动态发现的配置. 1. 静态配置 启动3个 broker,端口分别为61616,61618,61620, ...
- Lamda 表达式里的Join和GroupJoin的区别, 如何实现SQL的Left Join效果
例如,可以将产品表与产品类别表相联接,得到产品名称和与其相对应的类别名称 db.Products .Join ( db.Categories, p => p.CategoryID, c => ...
- 每天进步一点点out1
1● attend ətend 2● infant əfənd
- 学习笔记-AngularJs(二)
在接下来学习angularjs中,我按照的就是之前 学习笔记-AngularJs(一)所讲的目录来搭建一个学习的项目,做一个互联网大佬人物简介的例子,当然也可以使用angualrjs上面提供的官方例子 ...
- Python自然语言处理---信息提取
1.数据 目前的数据总体上分为结构化和非结构化的数据.结构化的数据是指实体和关系的规范和可预测的组织.大部分的需要处理的数据都属于非结构化的数据. 2.信息提取 简言之就是从文本中获取信息意义的方法. ...
- VS Code 常用快捷键
VS Code 常用快捷键 1.注释: 单行注释:ctrl+/, 注释后再按取消 取消单行注释:alt+shift+A 注释后再按取消 2.移动行 向上移动一行:alt+up 向下移动一行:alt+d ...
- Dev-cpp怎样去掉括号匹配?
很多编C/C++的同学在用Dev-cpp的时候,就感觉到括号匹配很烦,又不知道哪里去掉. 所以,让ljn告诉你怎样去掉括号匹配. 1.打开Dev-cpp. 2.在菜单栏上,点击“工具[T]”,选择“编 ...