CRB and Candies(组合数学+求逆元+lcm)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5407
题目:
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.
1 ≤ T ≤ 300
1 ≤ N ≤ 106
1
2
3
4
5
2
3
12
10
#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)的更多相关文章
- 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\) 题解: ...
- HDU 5407 CRB and Candies(LCM +最大素因子求逆元)
[题目链接]pid=5407">click here~~ [题目大意]求LCM(Cn0,Cn1,Cn2....Cnn)%MOD 的值 [思路]来图更直观: 这个究竟是怎样推出的.说实话 ...
- HDU 5407——CRB and Candies——————【逆元+是素数次方的数+公式】
CRB and Candies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- CRB and Candies LCM 性质
题目 CRB and Candies 题意 \[ \text{给定正整数N,求} LCM \lbrace C \left(N , 0 \right),C\left(N , 1 \right),..., ...
- bzoj4591 [Shoi2015]超能粒子炮·改——组合数学(+求阶乘逆元新姿势)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4591 这题不是很裸啊(所以我就不会了) 得稍微推导一下,看这个博客好了:https://bl ...
- 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][ ...
- 【HDOJ 5407】 CRB and Candies (大犇推导
pid=5407">[HDOJ 5407] CRB and Candies 赛后看这题题解仅仅有满眼的迷茫------ g(N) = LCM(C(N,0),C(N,1),...,C(N ...
- 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 ...
- CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)
Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...
随机推荐
- TCP系列10—连接管理—9、syncookie、fastopen与backlog
这部分内容涉及较多linux实现,可以跳过. 一.listen系统调用对backlog的处理 当socket处于LISTEN或者CLOSED状态时,fastopen队列的长度可以通过TCP_FASTO ...
- css那些事儿2 经典两列布局
<!DOCTYPE html> <html> <head> <title></title> <link rel="style ...
- 3dContactPointAnnotationTool开发日志(二四)
添加了清空2d接触点的按钮,将输出的2d接触点的单位变成了像素,原点在图像的左下角. 对于obj文件的适配更加多样化了.
- #Leetcode# 700. Search in a Binary Search Tree
https://leetcode.com/problems/search-in-a-binary-search-tree/ Given the root node of a binary search ...
- 字符串数组去重 ["a","b","c","a","b","c"] --> ["a","b","c"]
非正则实现: let str_arr=["a","b","c","a","b","c&qu ...
- python获取本地时间
python本地时间 import time # 格式化成2016-03-20 11:45:39形式 now = time.strftime("%Y-%m-%d %H:%M:%S" ...
- 解决XAMPP中,MYSQL因修改my.ini后,无法启动的问题
论这世上谁最娇贵,不是每年只开七天的睡火莲,也不是瑞典的维多利亚公主,更不是一到冬天就自动关机的iPhone 6s, 这世上最娇贵的,非XAMPP中的mysql莫属,记得儿时的我,年少轻狂,当时因为m ...
- C#下Label的多行显示
效果如图 1. tableLayout 三行两列 第一行 存放二维码的信息 第二行空白,用于分割 第三行存储LOGO信息 2. Lable4个,Dock属性都为Fill 第一列TextAlign使用M ...
- mysql学习之数据备份与恢复
该文使用mysql5.5 centos6.5 64位(本人使用rpm安装mysql,数据库的安装目录默认) 一.数据备份注意事项 读锁问题:数据库(或者某个表)一旦进行读锁操作则影响数据库的写操作所以 ...
- 向今天要结果; 向明天要动力 eclipse不自动弹出提示(alt+/快捷键失效)
最近公司电脑上的Eclipse没有了自动提示功能,也不是全部不提示,大多数情况下按下“alt+/”键还会产生提示,但是当我在java项目中邪main方法和syso的时候,“alt+/”则会失效,今天在 ...