<题目链接>

<转载于 >>> >

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
 

题目大意:

题目大意就是求 :    lcm(C(n,0),C(n,1),C(n,2),,,,C(n,n))

解题分析:

有一个对应的结论: lcm(C(n,0),C(n,1),C(n,2),,,,C(n,n))  =   lcm(1,2,,,,n,n+1)/(n+1)。

于是这道题就变成了求(1~n)的lcm,当然,直接暴力求解会超时,还有求LCM的更加高效的解法,叫做分解质因数法。并且,由于(n+1)可能很大,所以还要用到逆元的知识。

辅助理解的博客 >>> 

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <algorithm>
  4. #include <string.h>
  5. using namespace std;
  6. typedef long long LL;
  7. const int N = ;
  8. const LL mod = ;
  9. LL f[N];
  10. LL gcd(LL a,LL b){
  11. return b==?a:gcd(b,a%b);
  12. }
  13.  
  14. LL extend_gcd(LL a,LL b,LL &x,LL &y){
  15. if(!b){
  16. x=,y = ;
  17. return a;
  18. }else{
  19. LL x1,y1;
  20. LL d = extend_gcd(b,a%b,x1,y1);
  21. x = y1;
  22. y = x1 - a/b*y1;
  23. return d;
  24. }
  25. }
  26. LL mod_reverse(LL a,LL n)
  27. {
  28. LL x,y;
  29. LL d=extend_gcd(a,n,x,y);
  30. if(d==) return (x%n+n)%n;
  31. else return -;
  32. }
  33. int prime[N];
  34. LL F[N];
  35. bool only_divide(int n){
  36. int t = prime[n];
  37. while(n%t==){
  38. n/=t;
  39. }
  40. if(n==) return true;
  41. return false;
  42. }
  43. void init(){
  44. for(int i=;i<N;i++){
  45. prime[i] = i;
  46. }
  47. for(int i=;i<N;i++){ ///十分巧妙的一步,判断某个数是否只有唯一的质因子,只需要把每个数的倍数存下来
  48. if(prime[i]==i){
  49. for(int j=i+i;j<N;j+=i){
  50. prime[j] = i;
  51. }
  52. }
  53. }
  54. F[] = ;
  55. for(int i=;i<N;i++){
  56. if(only_divide(i)){
  57. F[i] = F[i-]*prime[i]%mod;
  58. }else F[i] = F[i-];
  59. }
  60. }
  61. int main()
  62. {
  63. init();
  64. int tcase;
  65. scanf("%d",&tcase);
  66. while(tcase--)
  67. {
  68. int n;
  69. scanf("%d",&n);
  70. LL inv = mod_reverse((n+),mod);
  71. printf("%lld\n",F[n+]*inv%mod);
  72. }
  73. return ;
  74. }

2018-07-30

hdu 5407【LCM性质】+【逆元】(结论题)的更多相关文章

  1. hdu 5407(LCM好题+逆元)

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

  2. HDU 5407(2015多校10)-CRB and Candies(组合数最小公倍数+乘法逆元)

    题目地址:pid=5407">HDU 5407 题意:CRB有n颗不同的糖果,如今他要吃掉k颗(0<=k<=n),问k取0~n的方案数的最小公倍数是多少. 思路:首先做这道 ...

  3. 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][ ...

  4. hdu4786 Fibonacci Tree[最小生成树]【结论题】

    一道结论题:如果最小生成树和最大生成树之间存在fib数,成立.不存在或者不连通则不成立.由于是01图,所以这个区间内的任何生成树都存在. 证明:数学归纳?如果一棵树没有办法再用非树边0边替代1边了,那 ...

  5. [codevs5578][咸鱼]tarjan/结论题

    5578 咸鱼  时间限制: 1 s  空间限制: 128000 KB   题目描述 Description 在广袤的正方形土地上有n条水平的河流和m条垂直的河流,发达的咸鱼家族在m*n个河流交叉点都 ...

  6. BZOJ_1367_[Baltic2004]sequence_结论题+可并堆

    BZOJ_1367_[Baltic2004]sequence_结论题+可并堆 Description Input Output 一个整数R Sample Input 7 9 4 8 20 14 15 ...

  7. [BZOJ3609][Heoi2014]人人尽说江南好 结论题

    Description 小 Z 是一个不折不扣的 ZRP(Zealot Round-game Player,回合制游戏狂热玩家), 最近他 想起了小时候在江南玩过的一个游戏.     在过去,人们是要 ...

  8. 【uoj#282】长度测量鸡 结论题

    题目描述 给出一个长度为 $\frac{n(n+1)}2$ 的直尺,要在 $0$ 和 $\frac{n(n+1)}2$ 之间选择 $n-1$ 个刻度,使得 $1\sim \frac{n(n+1)}2$ ...

  9. 【uoj#175】新年的网警 结论题+Hash

    题目描述 给出一张 $n$ 个点 $m$ 条边的无向连通图,每条边的边权为1.对于每个点 $i$ ,问是否存在另一个点 $j$ ,使得对于任意一个不为 $i$ 或 $j$ 的点 $k$ ,$i$ 到 ...

  10. 【uoj#180】[UR #12]实验室外的攻防战 结论题+树状数组

    题目描述 给出两个长度为 $n$ 的排列 $A$ 和 $B$ ,如果 $A_i>A_{i+1}$ 则可以交换 $A_i$ 和 $A_{i+1}$ .问是否能将 $A$ 交换成 $B$ . 输入 ...

随机推荐

  1. Java 学习札记(三)免安装版TomCat中tomcat6w.exe的运行

    1.使用环境 很多时候我们用的是官网的解压免安装版的Tomcat,相比安装Tomcat除了少了安装步骤以外还少了tomcat6w.exe运行所需要的环境变量,所以一般Java开发免安装版的已经足够使用 ...

  2. RabbitMQ运行机制

    AMQP中消息的路由过程和Java开发者熟悉的JMS存在一些差别,AMQP中增加了Exchange和Binding的角色,生产者把消息发布到Exchange上,Binding决定发布到Exchange ...

  3. List Control控件

    List Control控件 显示方式 属性[View]选择成[Report]. 添加成员变量 绑定变量:m_listCtrl 设置值 // 表头添加 m_listCtrl.SetExtendedSt ...

  4. linux 定期清除日志

    clearLog.sh #!/bin/sh find /usr/local/apache/logs -mtime + 30 -name "*.log" -exec rm {} \; ...

  5. spring data redis使用1——连接的创建

    spring data redis集成了几个Redis客户端框架,Jedis , JRedis (Deprecated since 1.7), SRP (Deprecated since 1.7) a ...

  6. 【bzoj1901】dynamic ranking(带修改主席树)

    传送门(权限) 传送门(非权限) 花了一晚上总算把代码调好了……才知道待修改主席树怎么操作…… 然而还是一知半解orz…… 先说说我的理解吧 我们一般建主席树的时候都是直接在序列上建的 但是如果有修改 ...

  7. HTTP SIP 认证

    HTTP请求报头: Authorization HTTP响应报头: WWW-Authenticate   HTTP认证  基于  质询  /回应(  challenge/response)的认证模式. ...

  8. Expm 7_2区间调度问题

    [问题描述] 给定n个活动,其中的每个活动ai包含一个起始时间si与结束时间fi.设计与实现算法从n个活动中找出一个最大的相互兼容的活动子集S. 要求:分别设计动态规划与贪心算法求解该问题.其中,对贪 ...

  9. C#面向对象(继承)

  10. pytorch实现花朵数据集读取

    import os from PIL import Image from torch.utils import data import numpy as np from torchvision imp ...