题目链接: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. osg::Vec2 Vec3 Vec4

    osg::Vec2可以用于保存2D纹理坐标. osg::Vec3是一个三维浮点数数组. osg::Vec4用于保存颜色数据.

  2. YaoLingJump开发者日志(八)V1.1版本完成

    跳跃吧瑶玲下载连接 官网下载(网站服务器不支持10M以上的文件上传-_-||) 百度网盘下载 介绍   忙里偷闲,把之前的工作整理了一下完成V1.1版本,下面是更新! (1)去掉了积分榜. (2)增加 ...

  3. 数论的欧拉定理证明 &amp; 欧拉函数公式(转载)

    欧拉函数 :欧拉函数是数论中很重要的一个函数,欧拉函数是指:对于一个正整数 n ,小于 n 且和 n 互质的正整数(包括 1)的个数,记作 φ(n) . 完全余数集合:定义小于 n 且和 n 互质的数 ...

  4. windows批处理学习---01

    一. 标记符号: CR(0D) 命令行结束符 Escape(1B) ANSI转义字符引导符 Space() 常用的参数界定符 Tab() ; = 不常用的参数界定符 + COPY命令文件连接符 * ? ...

  5. (转)linux IO 内核参数调优 之 参数调节和场景分析

    1. pdflush刷新脏数据条件 (linux IO 内核参数调优 之 原理和参数介绍)上一章节讲述了IO内核调优介个重要参数参数. 总结可知cached中的脏数据满足如下几个条件中一个或者多个的时 ...

  6. C++除法运算 // 静态断言

    1.C++中"/"运算:对两个整数做除法,结果仍为整数,如果它的商包含小数部分,则小树部分会被截除. C++ Primer 第五章 P130 2.静态断言(static_asser ...

  7. BZOJ 1066 蜥蜴(网络流)

    很普通的拆点网络流,把每个柱子拆成两个点(i,j,0)和(i,j,1).对于柱子的高度限制则加边((i,j,0),(i,j,1),height). 两个柱子能互相到达则加边((i,j,1),(i1,j ...

  8. Apple - Hdu5160

    Problem Description We are going to distribute apples to n children. Every child has his/her desired ...

  9. POJ1474:Video Surveillance——题解

    http://poj.org/problem?id=1474 题目大意:给按照顺时针序的多边形顶点,问其是否有内核. —————————————————————————————— (和上道题目一模一样 ...

  10. POJ3422:Kaka's Matrix Travels——题解

    http://poj.org/problem?id=3422 题目大意: 从左上角走到右下角,中途取数(数>=0),然后该点的数变为0,求走k的总价值和最大值. ———————————————— ...