码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5407 CRB and Candies

时间:2015-08-20 19:02:11      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:c语言   数学   公式   

传送门
http://oeis.org/A002944 http://oeis.org/A003418
an=LCM(C(n,0),C(n,1),C(n,2),...,C(n,n))
bn=LCM(1,2,3,...,n)
an=bn+1n+1
if (n=pk)bn=p?bn?1elsebn=bn?1

#include <bits/stdc++.h>
using namespace std;
#define prt(k) cerr<<#k" = "<<k<<endl
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const int N = 1000100;
ll p[N];
ll a[N];
bool ok(ll n)
{
    int t = p[n];
    while (n % t==0 && n > 1) n /= t;
    return n==1;
}
ll pmod(ll a, ll n)
{
    ll ret = 1;
    for (; n; n>>=1, a=a*a%mod) if (n & 1)
        ret = ret * a % mod;
    return ret;
}
ll inv(ll a)
{
    return pmod(a, mod - 2);
}
int main()
{
    for (int i=1;i<N;i++) p[i]=i;
    for (int i=2;i<N;i++) if (p[i]==i) {
        for (int j=i+i;j<N;j+=i) p[j] = i;
    }
    a[0] = 1;
    for (int i=1;i<N;i++) {
        if (ok(i))
            a[i] = a[i-1] * p[i] % mod;
        else
            a[i] = a[i-1];
    }
    int n; int re; cin>>re;
    while (re--) {
        scanf("%d", &n);
        n++;
        ll ans = a[n] * inv(n) % mod;
        printf("%I64d\n", ans);
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

HDU 5407 CRB and Candies

标签:c语言   数学   公式   

原文地址:http://blog.csdn.net/oilover/article/details/47811159

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!