Problem Description
Function Fx,ysatisfies:

For given integers N and M,calculate Fm,1 modulo 1e9+7.
 
Input
There is one integer T in the first line.
The next T lines,each line includes two integers N and M .
1<=T<=10000,1<=N,M<2^63.
 
Output
For each given N and M,print the answer in a single line.
 
Sample Input
2
2 2
3 3
 
Sample Output
2
33

数学题,反正我不会。。。数学基础太差了,直接用大佬的数学公式写的

参考博客: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(数学+乘法逆元)的更多相关文章

  1. 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 ...

  2. HDU 6140 17多校8 Hybrid Crystals(思维题)

    题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...

  3. HDU 6143 17多校8 Killer Names(组合数学)

    题目传送:Killer Names Problem Description > Galen Marek, codenamed Starkiller, was a male Human appre ...

  4. HDU 6045 17多校2 Is Derek lying?

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6045 Time Limit: 3000/1000 MS (Java/Others)    Memory ...

  5. HDU 6124 17多校7 Euler theorem(简单思维题)

    Problem Description HazelFan is given two positive integers a,b, and he wants to calculate amodb. Bu ...

  6. 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 ...

  7. HDU 6034 17多校1 Balala Power!(思维 排序)

    Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He want ...

  8. 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− ...

  9. 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. ...

随机推荐

  1. vue element upload图片 回显问题

      beforeUpload (file) { var _this = this; var reader = new FileReader(); reader.readAsDataURL(file); ...

  2. thinkphp3.1.3导入

    1.首先我们做导入一定要在我们的项目中导入一个   PHPExcel    下载地址:http://phpexcel.codeplex.com/ 2.下载之后就解压我们就可以看到像这样子的文件 3.就 ...

  3. 兼容IE8的video写法

    <video width="100%" height="515px" controls preload> <source src=" ...

  4. 转-MySQL教程-写的很详细,赞一个

    原帖地址:https://www.w3cschool.cn/mysql/,谢谢原帖大人 MySQL是什么? MySQL安装 MySQL示例数据库 MySQL导入示例数据库 MySQL基础教程 MySQ ...

  5. sku 加减号的增删

    ---恢复内容开始--- //php页面public function test(){ $id="1"; $data=Db::table('week3_goods') ->j ...

  6. servlet-api-2.4.jar not loaded(转)

    信息: validateJarFile(D:/xj/workspace/webworktest/webapp/WEB-INF/lib/servlet-api-2.4.jar) - jar not lo ...

  7. django学习之——我的 Hello World

    pycharm 打开django 创建的项目:添加views.py文件 修改 urls.py from django.conf.urls import patterns, include, url f ...

  8. 一个典型的多表参与连接的复杂SQL调优(SQL TUNING)引发的思考

    今天在看崔华老师所著SQL优化一书时,看到他解决SQL性能问题的一个案例,崔华老师成功定位问题并进行了解决.这里,在崔华老师分析定位的基础上,做进一步分析和推理,以便大家一起研究探讨,下面简述该案例场 ...

  9. EvalAI使用——类似kaggle的开源平台,不过没有kernel fork功能,比较蛋疼

    官方的代码 https://github.com/Cloud-CV/EvalAI 我一直没法成功import yaml配置举办比赛(create a challenge on EvalAI 使用htt ...

  10. 检测用户命令序列异常——使用LSTM分类算法【使用朴素贝叶斯,类似垃圾邮件分类的做法也可以,将命令序列看成是垃圾邮件】

    通过 搜集 Linux 服务器 的 bash 操作 日志, 通过 训练 识别 出 特定 用户 的 操作 习惯, 然后 进一步 识别 出 异常 操作 行为. 使用 SEA 数据 集 涵盖 70 多个 U ...