题解讲的很清楚了,直接看代码就懂了

题解:http://bestcoder.hdu.edu.cn/blog/2018-multi-university-training-contest-6-solutions-by-%e7%a6%8f%e5%b7%9e%e5%a4%a7%e5%ad%a6/

#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<map>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii; const ll mod = 1e9+;
const int N = 2e6+;
const double eps = 1e-;
const int inf = 0x3f3f3f3f; bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=;a%=mod; if(b<) return ; for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
ll x=,f=;char ch=getchar();
while (ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while (ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
ll inv[N], f[N], fac[N];
ll a[N];
void init() {
f[] = ; f[] = ;
fac[] = fac[] = ;
inv[]=;
rep(i, , N) {
fac[i] = fac[i-] * (ll)i % mod;
inv[i] = kpow(fac[i], mod-);
f[i] = (f[i-] * f[i-]) % mod;
}
}
ll C(int n, int m) {
if(n < m) return 0ll;
if(m== || n==m) return 1ll;
if(n-==m || m==) return n;
return fac[n] * inv[m] % mod * inv[n-m] % mod;
}
int main(){
init();
int T;
scanf("%d",&T);
while(T--) {
int n, m;
scanf("%d%d",&n,&m);
mt(a, );
ll sum = C(n+m-, n), ans = ;
repd(g,n,) {
if(n%g==) {
ll j = n / g;
a[g] = C(j+m-,j) % mod;
repp(k,g+g,n + ,g) a[g] = (a[g] - a[k] + mod) % mod;
ans = ans + a[g] * (f[g] - + mod) % mod; ans %= mod;
}
}
ans = ans * kpow(sum, mod-) % mod;
printf("%lld\n",ans);
}
return ;
}

hdu 6363 bookshelf的更多相关文章

  1. HDU 6363

    题意略. 思路: 这里有两个结论需要注意: 1.gcd(a ^ x - 1,a ^ y - 1) = a ^ gcd(x,y) - 1 2.gcd(fib[x],fib[y]) = fib[gcd(x ...

  2. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  4. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  5. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  7. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  8. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

随机推荐

  1. Vue.js Ajax动态参数与列表显示

    一.动态参数显示 1.引入js <script type="text/javascript" src="/js/vue.min.js"></s ...

  2. POJ 2386 Lake Counting【BFS】

    题意:给出一个矩形,问有多少块连通的W 当找到W的时候,进行广搜,然后将搜过的W变成点,直到不能再搜,进行下一次广搜,最后搜的次数即为水塘的个数 看的PPT里面讲的是种子填充法. 种子填充算法: 从多 ...

  3. ActiveMQ学习笔记(13)----Destination高级特性(一)

    1. Wildcards 1. Wildcards用来支持名字分层体系,它不是JMS规范的一部分,是ActiveMQ的扩展. ActiveMQ支持一下三种wildcards: 1. ".&q ...

  4. 洛谷P3567 [POI2014]KUR-Couriers 主席树

    挺裸的,没啥可讲的. 不带修改的主席树裸题 Code: #include<cstdio> #include<algorithm> using namespace std; co ...

  5. ES6学习笔记(二十)Module 的加载实现

    上一章介绍了模块的语法,本章介绍如何在浏览器和 Node 之中加载 ES6 模块,以及实际开发中经常遇到的一些问题(比如循环加载). 1.浏览器加载 传统方法 HTML 网页中,浏览器通过<sc ...

  6. 《剑指Offer》——试题1:赋值运算符函数

    题目:如下类型为CMyString的声明,请为该类型添加赋值运算符函数.   class CMyString { public: CMyString(char* pData = NULL); CMyS ...

  7. Fiddler 接口测试(Composer)的使用方法

    原文:Fiddler 接口测试(Composer)的使用方法 下载地址:https://www.telerik.com/download/fiddler 一.Composer简介 右侧Composer ...

  8. 洛谷 P1990 覆盖墙壁

    P1990 覆盖墙壁 题目描述 你有一个长为N宽为2的墙壁,给你两种砖头:一个长2宽1,另一个是L型覆盖3个单元的砖头.如下图: 0 0 0 00 砖头可以旋转,两种砖头可以无限制提供.你的任务是计算 ...

  9. POJ 2828 Buy Tickets(线段树&#183;插队)

    题意  n个人排队  每一个人都有个属性值  依次输入n个pos[i]  val[i]  表示第i个人直接插到当前第pos[i]个人后面  他的属性值为val[i]  要求最后依次输出队中各个人的属性 ...

  10. hdu-2871

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #i ...