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. 关于linux中用vi新建立一个.c文件无法保存,显示E212错误的时候

    在ubuntu16.04环境下,用vi新键.c文件,怎么保存也不能 先按ESC  然后:  在后wq  可是显示文件212错误. 后来知道在建立.c的文件夹的权限不对.这里的权限用 ls -l来查看 ...

  2. vivado第一天从建立文件运行小程序开始

    今天,是第一天什么也处于懵懂的时候,首要的任务就是建立一个文件 首先打开vivado运行软件, 如图所示,选择第一个create new project 来新建文件 选择存储路径,一路向下 当选择芯片 ...

  3. python-flask-请求源码流程

    启动先执行manage.py 中的    app.run() class Flask(_PackageBoundObject): def run(self, host=None, port=None, ...

  4. UI基础一:值节点赋值

    METHOD EH_ONSEARCH. *CALL METHOD SUPER->EH_ONSEARCH ** EXPORTING ** HTMLB_EVENT = ** HTMLB_EVENT_ ...

  5. Oracle中序列(Sequence)详解

    一 序列定义 序列(SEQUENCE)是序列号生成器,可以为表中的行自动生成序列号,产生一组等间隔的数值(类型为数字).不占用磁盘空间,占用内存. 其主要用途是生成表的主键值,可以在插入语句中引用,也 ...

  6. 三、存储过程(Stored Procedure)与游标(Cursor)

    一.存储过程 一组为了完成特定功能的SQL语句集,经编译后存储在数据库中,用户通过指定存储过程的名字并给出参数,来执行它. 在大型数据库中,存储过程和触发器具有重要的作用.无论是存储过程还是触发器,都 ...

  7. POJ 2373 Dividing the Path(DP + 单调队列)

    POJ 2373 Dividing the Path 描述 农夫约翰的牛发现,在他的田里沿着山脊生长的三叶草是特别好的.为了给三叶草浇水,农夫约翰在山脊上安装了喷水器. 为了使安装更容易,每个喷头必须 ...

  8. July_One_Week—linked list

    #include <stdio.h> #include <stdlib.h> typedef struct linklist { unsigned int count; str ...

  9. In-App Purchase iap 内付费 二次验证代码 (java 服务器端)

    参考网址:https://blog.csdn.net/a351945755/article/details/22919533 package com.yichangmao.buyVerify.Comm ...

  10. 未来Linux系统将是运维行业必备的技能之一

    关于linux,这个并不是每个人都能用或者需要用的,因为平时有很多人用电脑只是为了上上网,聊聊天,打打游戏,这个是完全不需要用linux的.关于linux,是不能用正常的大家所熟知的window来认知 ...