题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5407

题目:

Problem Description
CRB has N different candies. He is going to eat K candies.
He wonders how many combinations he can select.
Can you answer his question for all K(0 ≤ K ≤ N)?
CRB is too hungry to check all of your answers one by one, so he only asks least common multiple(LCM) of all answers.
 
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case there is one line containing a single integer N.
1 ≤ T ≤ 300
1 ≤ N ≤ 106
 
Output
For each test case, output a single integer – LCM modulo 1000000007(109+7).
 
Sample Input
5
1
2
3
4
5
 
Sample Output
1
2
3
12
10
 
题意:求C(n,0) ~C(n,n)的最小公倍数。
思路:结果是1~(n+1)的最小公倍数除以n+1,证明过程请按传送门~对于求1~n+1的最小公倍数其实就是将所有1~n+1内的所有素数的最大的落在该区间内的幂次相乘即可~
代码实现如下:
 #include <cstdio>
#include <cstring>
#include <iostream>
using namespace std; typedef long long ll;
const int maxn = 1e6 + ;
const int mod = 1e9 + ;
int t, n, len;
int p[maxn], is_prime[maxn]; void init() {
len = ;
for (int i = ; i < maxn; i++) {
p[i] = ;
}
p[] = p[] = ;
for (int i = ; i * i < maxn; i++) {
if (p[i]) {
for (int j = i * i; j < maxn; j += i) {
p[j] = ;
}
}
}
for(int i = ; i < maxn; i++) {
if(p[i]) {
is_prime[len++] = i;
}
}
} ll ModPow(ll x, ll p) {
ll rec = ;
while (p) {
if (p & ) rec = (ll) rec * x % mod;
x = (ll) x * x % mod;
p >>= ;
}
return rec;
} int main() {
init();
cin >> t;
while (t--) {
cin >> n;
ll ans = , tmp;
n++;
for (int i = ; i < len && is_prime[i] <= n; i++) {
tmp = ;
while (tmp * is_prime[i] <= n) {
tmp = tmp * is_prime[i];
}
ans = ans * tmp % mod;
}
cout << (ans * ModPow(n, mod - ) % mod) << endl;
}
return ;
}

CRB and Candies(组合数学+求逆元+lcm)的更多相关文章

  1. HDU5407 CRB and Candies 【LCM递推】

    HDU5407 CRB and Candies 题意: 计算\(LCM(C(n,0),C(n,1),C(n,2),\cdots,C(n,n-1),C(n,n))\) \(n\le 10^6\) 题解: ...

  2. HDU 5407 CRB and Candies(LCM +最大素因子求逆元)

    [题目链接]pid=5407">click here~~ [题目大意]求LCM(Cn0,Cn1,Cn2....Cnn)%MOD 的值 [思路]来图更直观: 这个究竟是怎样推出的.说实话 ...

  3. HDU 5407——CRB and Candies——————【逆元+是素数次方的数+公式】

    CRB and Candies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  4. CRB and Candies LCM 性质

    题目 CRB and Candies 题意 \[ \text{给定正整数N,求} LCM \lbrace C \left(N , 0 \right),C\left(N , 1 \right),..., ...

  5. bzoj4591 [Shoi2015]超能粒子炮·改——组合数学(+求阶乘逆元新姿势)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4591 这题不是很裸啊(所以我就不会了) 得稍微推导一下,看这个博客好了:https://bl ...

  6. Hdu 5407 CRB and Candies (找规律)

    题目链接: Hdu 5407 CRB and Candies 题目描述: 给出一个数n,求lcm(C(n,0),C[n,1],C[n-2]......C[n][n-2],C[n][n-1],C[n][ ...

  7. 【HDOJ 5407】 CRB and Candies (大犇推导

    pid=5407">[HDOJ 5407] CRB and Candies 赛后看这题题解仅仅有满眼的迷茫------ g(N) = LCM(C(N,0),C(N,1),...,C(N ...

  8. 2015 Multi-University Training Contest 10 hdu 5407 CRB and Candies

    CRB and Candies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  9. CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)

    Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...

随机推荐

  1. cmake & make

    大家都知道,写程序大体步骤为: 1.用编辑器编写源代码,如.c文件. 2.用编译器编译代码生成目标文件,如.o. 3.用链接器连接目标代码生成可执行文件,如.exe. 但如果源文件太多,一个一个编译时 ...

  2. 用svmpredict输出的结果为空

    源程序:

  3. Ehcache概念篇

    前言 缓存用于提供性能和减轻数据库负荷,本文在缓存概念的基础上对Ehcache进行叙述,经实践发现3.x版本高可用性不好实现,所以我采用2.x版本. Ehcache是开源.基于缓存标准.基于java的 ...

  4. 【python】Python 之 __new__() 方法与实例化

    本文转自:http://www.cnblogs.com/ifantastic/p/3175735.html __new__() 是在新式类中新出现的方法,它作用在构造方法建造实例之前,可以这么理解,在 ...

  5. 【bzoj2834】回家的路 分层图最短路

    题目描述 输入 输出 样例输入 2 1 1 2 1 1 2 2 样例输出 5 题解 分层图最短路 dis[i][0]表示到i为横向时起点到i的最短路,dis[i][1]表示到i为纵向时起点到i的最短路 ...

  6. hdu 1054 Strategic Game (二分匹配)

    Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. 转:Scipy入门

    Scipy入门 转:http://notes.yeshiwei.com/scipy/getting_started.html 本章节主要内容来自 Getting Started .翻译的其中一部分,并 ...

  8. [NOIP2017]逛公园 最短路图 拓扑序DP

    ---题面--- 题解: 挺好的一道题. 首先我们将所有边反向,跑出n到每个点的最短路,然后f[i][j]表示从i号节点出发,路径长比最短路大j的方案数. 观察到,如果图中出现了0环,那么我们可以通过 ...

  9. POJ3335:Rotating Scoreboard——题解

    http://poj.org/problem?id=3335 题目大意:给按照顺时针序的多边形顶点,问其是否有内核. —————————————————————————————— 看了两个小时的资料, ...

  10. kafka-zk-安装测试初体验

    第一步: 安装 安装工具brew install kafka 会自动安装依赖zookeeper 注:安装配置文件位置 /usr/local/etc/kafka|zookeeper 注: #tickTi ...