hdu 6363 bookshelf
题解讲的很清楚了,直接看代码就懂了
题解: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的更多相关文章
- HDU 6363
题意略. 思路: 这里有两个结论需要注意: 1.gcd(a ^ x - 1,a ^ y - 1) = a ^ gcd(x,y) - 1 2.gcd(fib[x],fib[y]) = fib[gcd(x ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
随机推荐
- PostgreSQL+PostGIS
PostGIS简介 PostGIS是对象关系型数据库系统PostgreSQL的一个扩展,PostGIS提供如下空间信息服务功能:空间对象.空间索引.空间操作函数和空间操作符.同时,PostGIS遵循O ...
- 编 写高性能的 SQL 语句注意事项
1. IS NULL 与 IS NOT NULL不能用 null 作索引, 任何包含 null 值的列都将不会被包含在索引中. 即使索引有多列这样的情况下,只要这些列中有一列含有 null,该列就会从 ...
- swift语言点评十-Value and Reference Types
结论:value是拷贝,Reference是引用 Value and Reference Types Types in Swift fall into one of two categories: f ...
- swift语言点评六-Numbers and Basic Values
Topics Logical Values struct Bool A value type whose instances are either true or false. Numeric Val ...
- ActiveMQ学习笔记(11)----ActiveMQ的动态网络连接
1. 多播协议multicast ActiveMQ使用Multicast协议将一个Service和其他的Broker是我Service里连接起来.IP Multicast是一个被用于网络中传输数据到其 ...
- VB创建文件夹
If Dir("D:\Program Files\AutoCAD 2006\Express\", vbDirectory) = "" Then '判断文件夹是否 ...
- 微信小程序的开启授权,当单机取消授权后 再次授权
//单机去搜索 toSearch:function(){ this.getLocation(res => { console.log('成功') wx.navigateTo({ url: `.. ...
- [Luogu]P3338 [ZJOI2014]力(FFT)
题目描述 给出\(n\)个数\(q_i\),给出\(F_j\)的定义如下: \(F_j = \sum_{i<j}\frac{q_i q_j}{(i-j)^2 }-\sum_{i>j}\fr ...
- JAVA SSL
http://docs.oracle.com/javase/1.5.0/docs/guide/security/jsse/JSSERefGuide.html#InstallationAndCustom ...
- MongoDB count distinct group by JavaAPI查询
import java.net.UnknownHostException; import com.mongodb.BasicDBList; import com.mongodb.BasicDBObje ...