//求1到n之间与n互质的数的四次方的和

//segma(n^4) = (6n^5+15n^4+10n^3-n)/30

//对于(a/b)%mod能够转化为(a*inv(b))%mod

//inv(b)为b的逆元

//由费马小定理a^(p-1) = 1(modp) a , p 互质可得

//30的逆元为30^(mod-2)

//由容斥原理非常easy得到与n不互质的数之和为

//对于全部的n的素数因子

//一个素数因子的全部数的四次方之和-有两个素数因子的全部数的四次方之和+有三个。

。。。

//然后用总的减去不互质的即为互质的

#include<cstdio>

#include<iostream>

#include<cstring>

using namespace std ;

const int maxn = 1010 ;

typedef __int64 ll ;

const __int64 mod = 1e9+7 ;

int p[maxn] ;

int len ;

ll  inv ;

void get_prime(ll n)

{

    len = 0 ;

    for(int i = 2;i*i <= n;i++)

    {

        if(n%i == 0)p[++len] = i;

        while(n%i==0)n/=i ;

    }

    if(n>1)p[++len] = n ;

}

ll Pow(ll a , ll b)

{

    ll c = 1 ;

    while(b)

    {

        if(b&1)c = (c*a)%mod;

        a = (a*a)%mod;

        b >>= 1;

    }

    return c ;

}

ll dfs(int pos , int n)

{

    ll ans = 0 ;

    for(int i = pos;i <= len ;i++)

    {

        ll t = n/p[i] ;

        ll t_1 = ((((6*Pow(t,5) + 15*Pow(t,4) + 10*Pow(t,3) - t))%mod)*inv)%mod;

        ans = (ans + (Pow(p[i] , 4)*(t_1- dfs(i+1 , n/p[i]))))%mod;

    }

    return ans ;

}

int main()

{

    int T ;

    scanf("%d" , &T) ;

    inv = Pow(30 , mod - 2) ;

    while(T--)

    {

        ll n ;

        scanf("%I64d" , &n) ;

        get_prime(n) ;

        ll ans = (((((6*Pow(n,5) + 15*Pow(n,4) + 10*Pow(n,3) - n))%mod)*inv)%mod - dfs(1 , n))%mod ;

        printf("%I64d\n" , (ans+mod)%mod);

    }

    return  0 ;

}

hdu4059The Boss on Mars 容斥原理的更多相关文章

  1. HDU 4059 The Boss on Mars 容斥原理

    The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU 4059 The Boss on Mars(容斥原理 + 四次方求和)

    传送门 The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  3. hdu4059 The Boss on Mars 容斥原理

    On Mars, there is a huge company called ACM (A huge Company on Mars), and it’s owned by a younger bo ...

  4. hdu4059 The Boss on Mars(差分+容斥原理)

    题意: 求小于n (1 ≤ n ≤ 10^8)的数中,与n互质的数的四次方和. 知识点: 差分: 一阶差分: 设  则    为一阶差分. 二阶差分: n阶差分:     且可推出    性质: 1. ...

  5. HDU 4059 The Boss on Mars(容斥原理)

    The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. The Boss on Mars

    The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. hdu 4059 The Boss on Mars

    The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. hdu4059 The Boss on Mars

    The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. 数论 + 容斥 - HDU 4059 The Boss on Mars

    The Boss on Mars Problem's Link Mean: 给定一个整数n,求1~n中所有与n互质的数的四次方的和.(1<=n<=1e8) analyse: 看似简单,倘若 ...

随机推荐

  1. [Visual Studio] VS2012调试时很慢的解决方案

      1.转自http://guooge.com/archives/408.html VS2010调试极慢获取出现死机,因为启动了IntelliTrace Visual Studio 2010 Ulti ...

  2. HDU 3436 Queue-jumpers (splay tree)

    Queue-jumpers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. XPROG-m编程器

    XPROG-m编程器是为取代较早版本的XPROG编程器而设计的. XPROG-m编程器硬件完全与XPROG编程器向上兼容,还具有其它许多功能. 该XPROG - M支持摩托罗拉68HC05,68HC0 ...

  4. Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls

    Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are ...

  5. web语义化,从松散到实战

    GitHub:http://liu12fei08fei.github.io/html/4semantic.html web语义化,从松散到实战 在这篇文章之前,我放弃了很多次,写关于语义化方面的文章: ...

  6. MVC文件上传05-使用客户端jQuery-File-Upload插件和服务端Backload组件自定义上传文件夹

    在零配置情况下,文件的上传文件夹是根目录下的Files文件夹,如何自定义文件的上传文件夹呢? MVC文件上传相关兄弟篇: MVC文件上传01-使用jquery异步上传并客户端验证类型和大小  MVC文 ...

  7. POJ 3740 Dancing Links

    Dancing Links学习:http://www.cnblogs.com/steady/archive/2011/03/15/1984791.html 以及图文学习:http://www.cnbl ...

  8. SVN环境

    SVN服务器搭建和使用(一) Subversion是优秀的版本控制工具,其具体的的优点和详细介绍,这里就不再多说. 首先来下载和搭建SVN服务器. 现在Subversion已经迁移到apache网站上 ...

  9. openshift 添加cron定时任务

    一般linux添加cron任务是在/etc/crontab,但是由于openshift的权限木有这么开放,所以如果需要设置定时任务的话,需要在如下的文件夹下添加你的sh文件,因为我需要的是每天运行一次 ...

  10. H264 RTP封包原理(转载)

    1.  引言        随着信息产业的发展,人们对信息资源的要求已经逐渐由文字和图片过渡到音频和视频,并越来越强调获取资源的实时性和互动性.但人们又面临着另外一种不可避免的尴尬,就是在网络上看到生 ...