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

BZOJ 4816: [Sdoi2017]数字表格

时间:2017-12-20 18:01:17      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:color   sdoi   long   return   turn   bzoj   pos   std   fine   

二次联通门 : BZOJ 4816: [Sdoi2017]数字表格

 

 

 

 

/*
    BZOJ 4816: [Sdoi2017]数字表格

    莫比乌斯反演

    妈呀,我的μ没有啦
    
*/
#include <cstdio>
#include <iostream>
#define rg register
#define Max 1000050
#define mo 1000000007
inline int min (int a, int b) { return a < b ? a : b; }
inline void read (int &n)
{
    rg char c = getchar ();
    for (n = 0; !isdigit (c); c = getchar ());
    for (; isdigit (c); n = n * 10 + c - 0, c = getchar ());
}
typedef long long LL;
LL f[Max], invf[Max];

LL pow (LL x, LL y)
{
    LL res = 1;
    for (; y; y >>= 1, (x *= x) %= mo)
        if (y & 1) (res *= x) %= mo;
    return res;
}
inline void pls (LL &a, LL b) { a += b; if (a >= mo) a -= mo; }
int main (int argc, char *argv[])
{
    rg int i, j; LL inv; int N, M, T;
    f[1] = 1;
    for (i = 2; i < Max; ++ i) pls (f[i], f[i - 1] + f[i - 2]);
    for (i = 1; i < Max; ++ i)
    {
        inv = pow (f[i], mo - 2);
        for (j = i << 1; j < Max; j += i) (f[j] *= inv) %= mo;
    }
    for (f[0] = i = 1; i < Max; ++ i) (f[i] *= f[i - 1]) %= mo;
    for (i = 0; i < Max; ++ i) invf[i] = pow (f[i], mo - 2);

    read (T); LL Answer;
    for (; T; -- T)
    {
        read (N), read (M); Answer = 1;
        if (N > M) std :: swap (N, M);
        for (i = 1; i <= N; i = j + 1)
        {
            j = min (N / (N / i), M / (M / i));
            (Answer *= pow (pow (f[j] * invf[i - 1] % mo, (LL) N / i), (LL) M / i)) %= mo;
        }
        printf ("%lld\n", Answer);
    }    
    return 0;
}

 

BZOJ 4816: [Sdoi2017]数字表格

标签:color   sdoi   long   return   turn   bzoj   pos   std   fine   

原文地址:http://www.cnblogs.com/ZlycerQan/p/8074665.html

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