题目链接: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. request.getRequestDispatcher不能实现页面跳转的原因

    我在JS里面写了个Ajax,传值给servlet,然后利用request.getRequestDispatcher(),打算跳转至另外一个页面.但是没有跳转成功,运行之后没反应. 在网上搜了资料发现, ...

  2. IIS安装出现“安装程序无法复制文件CONVLOG.EX_”的解决办法

    重新安装了一次IIS,结果就在重新安装的时候,出现安装程序无法复制文件CONVLOG.EX_,上网找了找资料,是因为secedit.sdb 数据库的问题,既然是因为这个文件的问题,那么我们就可以使用w ...

  3. DEDE去掉会员登录及注册验证码的方法

    1.登录打开member/index_do.php 删除245-250行,即: if(strtolower($vdcode)!=$svali || $svali=='') { ResetVdValue ...

  4. listBox和pictureBox的使用

    重要属性:pictureBox中SizeMode可以更改图像显示的尺寸大小. using System; using System.Collections.Generic; using System. ...

  5. BZOJ4310 跳蚤(后缀数组+二分答案)

    注意到答案一定是原串的子串,于是考虑造出SA,二分答案是第几小的子串.第k小子串很容易在SA上求出.之后计算使他成为最大子串至少要在几个位置切割,对每个字典序比答案大的后缀,找到所有合法切割位置(求l ...

  6. PowerDesigner 建表语句没出现字段描述

    填写了Name 还是没有 修改步骤如下:

  7. [Leetcode] maximun subarray 最大子数组

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  8. BZOJ1042 [HAOI2008]硬币购物 【完全背包 + 容斥】

    1042: [HAOI2008]硬币购物 Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 2924  Solved: 1802 [Submit][St ...

  9. 我的ACM参赛故事

    从我接触程序竞赛到现在应该有十多年了,单说ACM竞赛,从第一次非正式参赛到现在也差不多有7年多的样子.有太多的故事,想说的话,却一直没能有机会写下来.一方面是自己忙,一方面也是自己懒.所以很感谢能有人 ...

  10. 剑桥offer(41~50)

    41.题目描述 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). class Solution { pub ...