zoukankan      html  css  js  c++  java
  • 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
    ",(ans+M)%M);
        }
        return 0;
    }
    如有转载,请注明出处(http://www.cnblogs.com/lochan)
  • 相关阅读:
    强大的Resharp插件
    配置SPARK 2.3.0 默认使用 PYTHON3
    python3 数据库操作
    python3 学习中的遇到一些难点
    log4j的一个模板分析
    MYSQL内连接,外连接,左连接,右连接
    rabbitmq实战记录
    领域模型分析
    分布式系统学习笔记
    阿里开发规范 注意事项
  • 原文地址:https://www.cnblogs.com/lochan/p/3437965.html
Copyright © 2011-2022 走看看