//求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. 记一次帮朋友解决apache站点403错误的过程

    apache版本: [root@iZ25eby2utyZ web]# rpm -qa | grep httpd httpd-tools--.el6.centos..x86_64 httpd--.el6 ...

  2. OPENCV----在APP性能测试中的应用(一)

    应用项目:  APP的性能测试 应用场景:  APP启动速度  视频开播速度 加载速度  等~~ 缘来:  基于APP日志和UiAutomator的测试方案,测试结果不能直白且精确的反应,用户的体验 ...

  3. django源码(2.0.2)粗解之命令行执行

    前言 django的命令行在整个的django web开发中都会经常用到,而且是必须得用到.所以,能够了解下django的命令行实现其实是非常有帮助的. 如果大家比较关心django命令的详细说明和使 ...

  4. http://qurtyy.blog.163.com/blog/static/5744368120130221419244/

    我们先来看它的思路:把控制不透明度和控向上移动的动画分别存储在两个队列中,控制向上移动的队列按默认情况进行(在2000毫秒内完成),而不透明度的控制在1000毫秒内执行,但这个队列要晚于默认队列100 ...

  5. IDA Supported Processors

    IDA supports more than 50 families of processors. The source code of some of the processor modules i ...

  6. MVC使用StructureMap实现依赖注入Dependency Injection

    使用StructureMap也可以实现在MVC中的依赖注入,为此,我们不仅要使用StructureMap注册各种接口及其实现,还需要自定义控制器工厂,借助StructureMap来生成controll ...

  7. amfphp2.1.1的使用经过

    这两天看了一个FLASH的教程,是arrowyong写的名为 <<ActionScript3.0从零基础学习类>>,这个教程好用,没有ActionScript编程经验的人,可以 ...

  8. Google In-App Billing 实现(内含Unity 实现经验)

    实现内购计费 傻逼目录   Adding the AIDL file Updating Your Manifest Creating a ServiceConnection Making In-app ...

  9. arcgis runtime 100 Create geometries

    1 /* Copyright 2016 EsriEsri 2 * 3 * Licensed under the Apache License, Version 2.0 (the "Licen ...

  10. jquery 判断元素是否存在于数组中

    要判断数组中是否包含某个元素,从原理来来说,就是遍历整个数组,然后判断是否相等 可以使用Jquery提供的方法: $.inArray("元素(字符串)",数组名称) 进行判断 ,当 ...