//求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. Perforce-Server迁移

    Author: JinDate: 20140827System: Windows 2008 R2 从Windows 2008 R2迁移到Windows 2008 R2 linux版本迁移官方文档htt ...

  2. max_binlog_cache_size

    http://blog.mimvp.com/2017/07/mysql-yi-ge-can-shu-yin-qi-de-dang-ji-xue-an/ max_binlog_cache_size 表示 ...

  3. Java工程师成神之路 转

      一.基础篇 1.1 JVM 1.1.1. Java内存模型,Java内存管理,Java堆和栈,垃圾回收 http://www.jcp.org/en/jsr/detail?id=133 http:/ ...

  4. Windows+VS2012环境下编译调试MySQL源码 转

    http://m.blog.csdn.net/blog/SnowyWolf/18952643

  5. java 盒子模型

    http://www.cnblogs.com/xiaohuochai/tag/javascript%E6%80%BB%E7%BB%93/

  6. Windows Performance Toolkit

    http://bigasp.com/archives/606 https://randomascii.wordpress.com/category/xperf/ ADK 8.0  (C:\Progra ...

  7. maven切换到阿里云镜像

    maven默认去中央仓库下载jar速度奇慢,切换成阿里的镜像源会快很多 maven  settings.xml配置 <?xml version="1.0" encoding= ...

  8. android软件中加入广告实现方法

    经过了一番折腾,忙忙碌碌了一下午,终于搞明白了Android软件界面嵌入广告的方法,以下我以嵌入有米广告为例小结一下: 步骤一,下载有米广告SDK,将 youmi-android.jar 导入想要嵌入 ...

  9. 如何优化JAVA代码

    通过使用一些辅助性工具来找到程序中的瓶颈,然后就可以对瓶颈部分的代码进行优化.一般有两种方案:即优化代码或更改设计方法.我们一般会选择后者,因为不去调用以下代码要比调用一些优化的代码更能提高程序的性能 ...

  10. C# 模拟网站登陆

    实现此功能首先需要借助一些抓包工具,对相应的网站登陆过程进行分析,此过程根据网站的不同,可能复杂,也可能很简单.常用的抓包工具FF下FireBug和IE下的HttpWatch.这两个工具很强大,以此工 ...