HDU4059_The Boss on Mars

数论题。

首先我们知道公式:1^4+2^4+3^4+……+n^4=(n)*(n+1)*(2*n+1)*(3*n*n+3*n-1) /30;

然后我们要把多余的减掉。这里用到的是mobius反演。

总之就是加加减减就可以出答案了。

 

 

#include <iostream>
#include <cstring>
#include <cstdio>
#define ll long long
#define M 1000000007
using namespace std;

ll power(ll x,ll y)
{
    ll tot=1;
    while (y)
    {
        if (y&1) tot=(tot*x)%M;
        x=(x*x)%M;
        y>>=1;
    }
    return tot;
}

ll over=power(30,M-2);

ll count(ll x)
{
    ll ans=x;
    ans=(ans*(x+1))%M;
    ans=(ans*(2*x+1))%M;
    ll tep=(3*x*x+3*x-1)%M;
    ans=(ans*tep)%M;
    ans=(ans*over)%M;
    return ans;
}

ll sqrr(ll x)
{
    return (x*x)%M;
}

ll mobi(ll x)
{
    ll k=x,tot=0;
    for (ll i=2; i*i<=k; i++)
    {
        if (k%i==0)
        {
            if (k%(i*i)==0) return 0;
            tot++,k/=i;
        }
    }
    if (k>1) tot++;
    if (tot&1) return 1;
    return -1;
}

int main()
{
    ll t,n,ans;
    scanf("%I64d",&t);
    while (t--)
    {
        scanf("%I64d",&n);
        ans=count(n-1);  
        for (int i=2; i*i<=n; i++)
            if (n%i==0)
            {
                ll tep=sqrr(sqrr(i))*count(n/i-1);
                tep%=M;
                ans=(ans-mobi(i)*tep)%M;
                if (i*i==n) continue;

                tep=sqrr(sqrr(n/i))*count(i-1);
                tep%=M;
                ans=(ans-mobi(n/i)*tep)%M;
            }
        printf("%I64d\n",(ans+M)%M);
    }
    return 0;
}

 

posted @ 2013-11-22 17:14  092000  阅读(304)  评论(0编辑  收藏  举报