HDU 5407

题意 : 给你一个 N 求 C(N,1 to N ) 的LCM;

有定理: (不会推)

哭泣的脸

g (n ) = C(N,1 to N ) 的LCM,   

f  (n  )   = Lcm ( 1, to  n)

g ( n ) = f(n + 1 ) / ( n + 1 );

f ( n ) =  f (n –1 ) * p  (( if  n 为 质数 p 的k 次方数)

         or  = f (n – 1 );

根据上式就可以很快得出 g (n )了;

#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int maxn = 1e6 +131;
const ll  mod = 1e9 + 7;
int Prime[maxn];
bool Jug[maxn];
int Cnt;
void Make()
{
    Cnt = 0;
    for(int i = 2; i < maxn; ++i)
    {
        if(Jug[i] == false)
        {
            Prime[Cnt++] = i;
            for(int j = i; j < maxn; j += i)
                Jug[j] = true;
        }
    }
}

ll Fun[maxn];
void MK()
{
    Fun[1] = 1;
    for(int i = 2; i < maxn; ++i)
    {
        int tmp = i;
        bool jj = true;
        for(int j = 0; j j)
        {
            if(tmp % Prime[j] == 0)
            {
                while(tmp % Prime[j] == 0) tmp /= Prime[j];
                if(tmp > 1) jj = false;
                break;
            }
        }
        if(jj) Fun[i] = Fun[i-1] * i % mod;
        else Fun[i] = Fun[i-1];
    }
}

ll ppow(ll a, ll b)
{
    ll ret = 1;
    while(b)
    {
        if(b & 1) ret = ret * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ret;
}

int main()
{
    Make();
    //MK();
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        ll ans = 1;
        for(int i = 0; i < Cnt && Prime[i] <= n; ++i)
        {
            ll tmp = Prime[i];
            while(tmp <= n)
            {
                if((n+1) % tmp != 0)
                    ans = ans * Prime[i] % mod;
                tmp = tmp * Prime[i];
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}

你可能感兴趣的:(数论)