【HDOJ 5407】 CRB and Candies (大犇推导
pid=5407">【HDOJ 5407】 CRB and Candies
赛后看这题题解仅仅有满眼的迷茫………………
g(N) = LCM(C(N,0),C(N,1),...,C(N,N))
f(n)\
=\ LCM(1, 2, ..., n)f(n) = LCM(1,2,...,n),
the fact g(n)\
=\ f(n+1) / (n+1)g(n) = f(n+1)/(n+1)
f(n)\ =\ LCM(1, 2, ..., n)f(1)
= 1
If n\
=p^{k}n =pk then f(n)\
=\ f(n-1) \times \ pf(n) = f(n−1)× p,
else f(n)\
=\ f(n-1)f(n) = f(n−1).
和不断的woc…… 后来QAQ巨找到了推导的文章。
。。
恩……贴上来……
http://www.zhihu.com/question/34859879
感觉我有公式恐惧症。。
。
看到长串公式就犯晕= = 巨巨们研究研究吧…………
感觉依据题解能做出来已经非常好了
事实上这题另一点是要取余 因为须要取余 不能做除法 因此要求个分母的乘法逆元 刚好在攻数论的扩欧,扩欧小费马都能做 前一篇有扩欧的不错的帖子链接 有兴趣的能够去瞅瞅
本题代码例如以下:
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std;
#define sz 1000000
#define ll long long
const int mod = 1e9+7; int p[sz+1];
ll f[sz+1]; bool ok(ll x)
{
int t = p[x];
while(x%t == 0 && x > 1) x /= t;
return x == 1;
} void Init()
{
int i,j;
for(i = 1; i <= sz; ++i) p[i] = i;
for(i = 2; i <= sz; ++i)
if(p[i] == i)
for(j = i+i; j <= sz; j += i)
if(p[j] == j) p[j] = i; f[0] = 1;
for(i = 1; i <= sz; ++i)
{
if(ok(i)) f[i] = f[i-1]*p[i]%mod;
else f[i] = f[i-1];
}
}
//扩欧
//int e_gcd(int a,int b,int &x,int &y)
//{
// if(!b)
// {
// x = 1;
// y = 0;
// return a;
// }
// ll tmp = x,ans = e_gcd(b,a%b,x,y);
// tmp = x;
// x = y;
// y = tmp - a/b*y;
// return ans;
//} ll pow(ll a,int m)
{
ll ans = 1;
for(;m; m >>= 1, a= a*a%mod)
if(m&1) ans = ans*a%mod;
return ans;
} ll cal(int a,int m)
{
//扩欧
// int x,y;
// int gcd = e_gcd(a,m,x,y);
// return (x/gcd+m)%m;
//小费马
return pow(a,m-2);
} int main()
{
Init();
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
printf("%lld\n",f[n+1]*cal(n+1,mod)%mod);
}
return 0;
}
【HDOJ 5407】 CRB and Candies (大犇推导的更多相关文章
- 数论 HDOJ 5407 CRB and Candies
题目传送门 题意:求LCM (C(N,0),C(N,1),...,C(N,N)),LCM是最小公倍数的意思,C函数是组合数. 分析:先上出题人的解题报告 好吧,数论一点都不懂,只明白f (n + 1) ...
- 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][ ...
- HDU 5407——CRB and Candies——————【逆元+是素数次方的数+公式】
CRB and Candies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- 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 ...
- HDU 5407 CRB and Candies(LCM +最大素因子求逆元)
[题目链接]pid=5407">click here~~ [题目大意]求LCM(Cn0,Cn1,Cn2....Cnn)%MOD 的值 [思路]来图更直观: 这个究竟是怎样推出的.说实话 ...
- LCM性质 + 组合数 - HDU 5407 CRB and Candies
CRB and Candies Problem's Link Mean: 给定一个数n,求LCM(C(n,0),C(n,1),C(n,2)...C(n,n))的值,(n<=1e6). analy ...
- HDU 5407 CRB and Candies
题意:给一个正整数k,求lcm((k, 0), (k, 1), ..., (k, k)) 解法:在oeis上查了这个序列,得知答案即为lcm(1, 2, ..., k + 1) / (k + 1),而 ...
- hdu 5407 CRB and Candies(组合数+最小公倍数+素数表+逆元)2015 Multi-University Training Contest 10
题意: 输入n,求c(n,0)到c(n,n)的所有组合数的最小公倍数. 输入: 首行输入整数t,表示共有t组测试样例. 每组测试样例包含一个正整数n(1<=n<=1e6). 输出: 输出结 ...
- CRB and Candies LCM 性质
题目 CRB and Candies 题意 \[ \text{给定正整数N,求} LCM \lbrace C \left(N , 0 \right),C\left(N , 1 \right),..., ...
随机推荐
- android 九宫格(16宫格)控件
public class NineRectView extends ViewGroup { private Context ctx; private int wSize,hSize,row,colum ...
- Unity3D_c#脚本注意要点
1. Inherit from MonoBehaviour 继承自MonoBehaviour All behaviour scripts must inherit from MonoBehaviour ...
- Mac OSX Yosemite 10.10 brew 错误:mktemp: mkdtemp failed on /tmp/git-LIPo: No such file or directory
这个问题困扰了我非常久非常久.使得我不得不花一点时间来说一下解决方法. 事情是这种:前两天兴高採烈的更新了一下宝贝mac到10.10. 一切看起来都那么美好,可是. .当我又一次安装magento的时 ...
- 客户端通过wcf来启动或者停止服务器上的windows service
1.设置服务器上的windows service的security,下面的命令只能用cmd.exe来运行(以管理员模式) sc sdset "LISA_43_Dev_Batch" ...
- NumPy和Pandas常用库
NumPy和Pandas常用库 1.NumPy NumPy是高性能科学计算和数据分析的基础包.部分功能如下: ndarray, 具有矢量算术运算和复杂广播能力的快速且节省空间的多维数组. 用于对整组数 ...
- Android 多个APK共享数据
Android给每个APK进程分配一个单独的用户空间,其manifest中的userid就是对应一个Linux用户(Android 系统是基于Linux)的.所以不同APK(用户)间互相访问数据默认是 ...
- css3子级高度与父级同高,内容垂直居中
.E-wrap{ overflow: hidden; position: relative; border: 1px solid #ccc; margin: 30px auto 0; width: 5 ...
- DateUtil时间工具类
package utils; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util. ...
- Mac-O文件加载的全过程(一)
在Mac的开发中, 有没有想过当我们点击可执行文件之后,Mac究竟做了什么事情才让我们的程序运行起来? 对于应用层开发人员或者普通的用户而言, 其实无需知道的这么详细:但是对于内核开发人员而言, 如果 ...
- ZBrush中Blob点滴笔刷介绍
对于ZBrush®来说,笔刷的使用时至关重要的,ZBrush中给我们提供了越来越多的笔刷的同时,我们也要根据经验来合理选择笔刷.本文内容小编将分享Blob点滴笔刷的简单介绍,该笔刷在使用时笔头犹如一股 ...