//求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. jProfiler远程连接Linux监控jvm的运行状态

    第一步:下载软件官网地址:https://www.ej-technologies.com/download/jprofiler/files,下载一个linux服务端,一个windows客户端 GUI界 ...

  2. python知识(3)----正则表达式

    python的正则表达式使用起来非常的方便,基本思路就是编译规则,匹配字符串,输出字符串 参考资料 Python中的正则表达式教程

  3. javaresource 红色X

    出现这个问题的原因很多,解决办法也很多,我这里只记录我所遇到的. 这个问题一直存在,但是不影响项目运行. 后来在网上找了下资料,有一篇文章是让修改maven的settings.xml.将jdk1.6修 ...

  4. tomcat-调整内存参数

    查看Tomcat的默认内存参数: <% /; /; /; out.println("max="+max); out.println("total="+to ...

  5. RAD Studio 2010~XE8 官方 ISO 下载地址 (2015-03-28更新)

    http://bbs.csdn.net/topics/390816856 RAD Studio XE8 目前最新版 v22.0.19027.8951 官方 ISO 文件下载(6.72GB):http: ...

  6. Quartz实现动态定时任务

    一. 说明 由于最近工作要实现定时任务的执行,而且要求定时周期是不固定的,所以就用到了quartz来实现这个功能: spring3.1以下的版本必须使用quartz1.x系列,3.1以上的版本才支持q ...

  7. ASP.NET中Cookie跨域的问题及解决代码

    ASP.NET中Cookie跨域的问题及解决代码 http://www.liyumei.net.cn/post/share18.html Cookies揭秘  http://www.cnblogs.c ...

  8. “CObject::operator =”: 无法访问 private 成员(在“CObject”类中声明)

    c++工程编译报错: “CObject::operator =”: 无法访问 private 成员(在“CObject”类中声明) 错误无法直接定位源码位置,网上搜索了,也和我的代码不一样. 最后还是 ...

  9. linux 查找文件命令

    find -name 文件名    在当前目录下查找 find -name nginx.conf

  10. Spring Framework 4.0.0发布,首次支持Java 8

    Spring项目组今天发布了Spring 框架4.0.0版本.Spring是一个开源的轻量级Java SE和Java EE开发应用框架,其目的是用于简化企业级应用程序开发. Spring框架第一个版本 ...