数学--数论--Hdu 5793 A Boring Question (打表+逆元)
There are an equation.
∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=?
We define that (kj+1kj)=kj+1!kj!(kj+1−kj)! . And (kj+1kj)=0 while kj+1<kj.
You have to get the answer for each n and m that given to you.
For example,if n=1,m=3,
When k1=0,k2=0,k3=0,(k2k1)(k3k2)=1;
Whenk1=0,k2=1,k3=0,(k2k1)(k3k2)=0;
Whenk1=1,k2=0,k3=0,(k2k1)(k3k2)=0;
Whenk1=1,k2=1,k3=0,(k2k1)(k3k2)=0;
Whenk1=0,k2=0,k3=1,(k2k1)(k3k2)=1;
Whenk1=0,k2=1,k3=1,(k2k1)(k3k2)=1;
Whenk1=1,k2=0,k3=1,(k2k1)(k3k2)=0;
Whenk1=1,k2=1,k3=1,(k2k1)(k3k2)=1.
So the answer is 4.
Input
The first line of the input contains the only integer T,(1≤T≤10000)
Then T lines follow,the i-th line contains two integers n,m,(0≤n≤109,2≤m≤109)
Output
For each n and m,output the answer in a single line.
Sample Input
2
1 2
2 3
Sample Output
3
13
打表很容易看出规律是m0+m1+...+mnm^0+m^1+...+m^nm0+m1+...+mn(鬼扯,我看了好几个小时愣是没看出有什么规律,看完题解还是不知道怎么推出来的,我太难了,这公式推的我服气)
下面是题解,我服我服了,卧槽。

推导公式结束后,你看直接一个逆元完事了,这个题我哭了,比我看到莫比乌斯反演还绝望,卧槽。
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long ksm(long long a, long long n)
{
long long ans = 1;
for (; n; n >>= 1)
{
if (n & 1)
ans = ans * a % mod;
a = a * a % mod;
}
return ans;
}
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
long long n, m;
scanf("%lld%lld", &n, &m);
printf("%lld\n", (ksm(m, n + 1) - 1) * ksm(m - 1, mod - 2) % mod);
}
return 0;
}
数学--数论--Hdu 5793 A Boring Question (打表+逆元)的更多相关文章
- HDU 5793 - A Boring Question
HDU 5793 - A Boring Question题意: 计算 ( ∑(0≤K1,K2...Km≤n )∏(1≤j<m) C[Kj, Kj+1] ) % 1000000007=? (C[ ...
- HDU 5793 A Boring Question (找规律 : 快速幂+逆元)
A Boring Question 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5793 Description Input The first l ...
- HDU 5793 A Boring Question (逆元+快速幂+费马小定理) ---2016杭电多校联合第六场
A Boring Question Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- HDU 5793 A Boring Question (找规律 : 快速幂+乘法逆元)
A Boring Question Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- hdu 5793 A Boring Question(2016第六场多校)
A Boring Question Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- HDU 5793 A Boring Question ——(找规律,快速幂 + 求逆元)
参考博客:http://www.cnblogs.com/Sunshine-tcf/p/5737627.html. 说实话,官方博客的推导公式看不懂...只能按照别人一样打表找规律了...但是打表以后其 ...
- HDU 5793 A Boring Question 多校训练
There are an equation. ∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=?∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1 ...
- 数学--数论--HDU 2582 F(N) 暴力打表找规律
This time I need you to calculate the f(n) . (3<=n<=1000000) f(n)= Gcd(3)+Gcd(4)+-+Gcd(i)+-+Gc ...
- hdu_5793_A Boring Question(打表找规律)
题目链接:hdu_5793_A Boring Question 题意: 自己看吧,说不清楚了. 题解: 打表找规律 #include<cstdio> typedef long long l ...
随机推荐
- bootstraptable 必备知识点
1.如何动态刷新表中数据? (1).无参刷新: $("#table").bootstrapTable('refresh'); (2).带参刷新: var opt = { url: ...
- 正则表达式 regex
正则表达式存在于String api下的matches方法 常用正常表达式: 字符 x 字符 x \\ 反斜线字符 字符类 [abc] a.b 或 c(简单类) [^abc] 任何字符,除了 a.b ...
- "文本加粗"组件:<b> —— 快应用组件库H-UI
 <import name="b" src="../Common/ui/h-ui/text/c_tag_b"></import> &l ...
- 【python实现卷积神经网络】优化器的实现(SGD、Nesterov、Adagrad、Adadelta、RMSprop、Adam)
代码来源:https://github.com/eriklindernoren/ML-From-Scratch 卷积神经网络中卷积层Conv2D(带stride.padding)的具体实现:https ...
- 萌新带你开车上p站(三)
本文作者:萌新 前情回顾: 萌新带你开车上p站(一) 萌新带你开车上p站(二) 0x08 题目给的提示是和运算符优先级有关 登录后直接看源码 mistake@pwnable:~$ ls flag mi ...
- 微信小程序页面通信
目录 微信小程序页面通信 方式一:通过URL 方式二:通过全局变量 方式三:通过本地存储 方式四:通过路由栈 微信小程序页面通信 方式一:通过URL // A 页面 wx.navigateTo({ u ...
- Android 开发小零碎
1.EditText默认就会自动获取焦点, 如何让EditText不自动获取焦点? 解决之道:在EditText的父级控件中找一个,设置成 android:focusable="true&q ...
- 怎么在执行Python脚本时,密码等敏感信息也不让它出现
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取http ...
- Java数组 —— 八大排序
(请观看本人博文--<详解 普通数组 -- Arrays类 与 浅克隆>) 在本人<数据结构与算法>专栏的讲解中,本人讲解了如何去实现数组的八大排序. 但是,在讲解的过程中,我 ...
- Os-Hax: 1 靶机记录
靶机地址:172.16.1.197 Kali地址:172.16.1.108 1 信息搜集 靶机首页 相关信息查看 端口扫描: 开放22和80 目录扫描: 访问http://172.16.1.197/c ...