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. Git-解释“Swap file .MERGE_MSG.swp already exists”的问题

    当合并代码时非正常保存退出遇到的问题. 博客原文: https://blog.csdn.net/qq_32452623/article/details/78395832

  2. springBoot配置,贴个图

    spring: datasource: name: test url: jdbc:mysql://localhost:3306/epay?characterEncoding=UTF-8 usernam ...

  3. 函数使用一:采购订单BAPI_PO_CREATE1

    REPORT YTEST01. DATA:GS_POHEADER TYPE BAPIMEPOHEADER, GS_POHEADERX TYPE BAPIMEPOHEADERX, GT_RETURN T ...

  4. Golang 在 Mac、Linux、Windows 下如何交叉编译(转)

    原文地址:Golang 在 Mac.Linux.Windows 下如何交叉编译 Golang 支持交叉编译,在一个平台上生成另一个平台的可执行程序,最近使用了一下,非常好用,这里备忘一下. Mac 下 ...

  5. Spring注解之BeanPostProcessor与InitializingBean

    /*** BeanPostProcessor 为每个bean实例化时提供个性化的修改,做些包装等*/ package org.springframework.beans.factory.config; ...

  6. CP-ABE的使用

    参考: http://acsc.cs.utexas.edu/cpabe/tutorial.html http://acsc.cs.utexas.edu/cpabe/ 事先先配置好cp-abe:http ...

  7. Python3红楼梦人名出现次数统计分析

    一.程序说明 本程序流程是读取红楼梦txt文件----使用jieba进行分词----借助Counter读取各人名出现次数并排序----使用matplotlib将结果可视化 这里的统计除了将“熙凤”出现 ...

  8. SpringBoot与docker

    1.简介 Docker是一个开源的应用容器引擎: Docker支持将软件编译成一个镜像:然后在镜像中各种软件做好配置,将镜像发布出去,其它使用者开源直接使用这个镜像: 运行中的这个镜像称为容器,容器启 ...

  9. 隔行变色&&鼠标移入变色

    <html lang="en"> <head> <meta charset="UTF-8"> <title>Do ...

  10. WPF实现DoEvents

    WPF实现DoEvents 原创 2011年06月30日 12:23:00 标签: wpf / object 2550 static void DoEvents() { DispatcherFrame ...