hdu 5407 组合数的lcm

</pre><p></p><p style="font-size:18px"></p><p style="font-size:18px"></p></h3><h3 class="t c-gap-bottom-small" style="margin:0px 0px 5px; padding:0px; list-style:none"><span style="font-size:18px"><a target=_blank target="_blank" href="http://acm.hdu.edu.cn/showproblem.php?pid=5411">hdu 5407</a> 本题求对于给定数n,求n的所有组合数的最小公倍数</span></h3><p></p><p><span style="font-size:18px">若c|a且b|a, 则lcm(a/c, a/b) = a/gcd(c, b);</span></p><p><span style="font-size:18px">因此</span></p><p><span style="font-size:18px">lcm(n!/0!n!,  n!/1!(n-1)!,  n!/2!(n-1)!,  n!/i!(n-i)!.....) =</span></p><p><span style="font-size:18px"> n ! / gcd(0!n!,   1!(n-1)!,   2!(n-1)!,   i!(n-i)!.....)</span></p><p></p><p><span style="font-size:18px">n!中个质因子p的次数为∑_(j=1)^∞[n/p^j ]</span></p><p><span style="font-size:18px"> i!(n-i)!中质因子p的次数为∑_(j=1)^∞[i/p^j +(n-i)/p^j ]</span></p><p></p><p><span style="font-size:18px">当且仅当(n+1)%(p^j)==0  对于任意的i, n/p^j == i/p^j+ (n-i)/p^j</span></p><p><span style="font-size:18px">所以只要(n+1)%(p^j) !=0 必有一个i使得n/p^j > i/p^j+ (n-i)/p^j 且 n/p^j - i/p^j - (n-i)/p^j  = 1;即分子会比分母多一个p</span></p><p></p><p><span style="font-size:18px">因此只要有一个(n+1)%(p^j) !=0 ,答案就多乘一个p</span></p><p><span style="font-size:18px"></span></p><p><strong><span style="font-size:18px">齿刚唇柔,刚者不如柔者久,柔能克刚; 眉先须后,先生还是后生长 ,后来居上</span></strong><pre name="code" class="cpp">#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <queue>
#define MAXN 1000010
#define ll long long
using namespace std;
const ll mod = 1000000007;
int prim[MAXN];
bool vis[MAXN];
int tot;
void work()
{
    memset(vis, 0, sizeof(vis));
    tot = 0;
    prim[tot++] = 2;
    int t = 1000000;
    for(int i = 3; i <= t; i+= 2)
    {
        if(vis[i]) continue;
        for(ll j = (ll)i*i; j <= t; j += 2*i)
            vis[j] = true;
        prim[tot++] = i;
    }
}
int main()
{
    work();
    //freopen("in.txt", "r", stdin);
    int t;
    cin >> t;
    while (t--)
    {
        ll ans = 1;
        int n;
        scanf("%d", &n);
        int tag = 0;
        for (int i=0; i<tot; i++)
        {
            ll tmp = prim[i];
            while (tmp <= n)
            {
                if ((n+1)%tmp!=0)
                    ans = ans*prim[i]%mod;
                tmp *= prim[i];
            }
        }
        printf("%I64d\n", ans);
    }
    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值