//求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. 最小生成树-普利姆算法eager实现

    算法描述 在普利姆算法的lazy实现中,参考:普利姆算法的lazy实现 我们现在来考虑这样一个问题: 我们将所有的边都加入了优先队列,但事实上,我们真的需要所有的边吗? 我们再回到普利姆算法的lazy ...

  2. 使用Device IO Control 讀寫 USB Mass Storage

    http://www.ezblog.idv.tw/Download/USBStorage.rar 這是一個不透過檔案系統,去讀寫USB Mass Storage 任何位置(包含FAT)的方式 首先需安 ...

  3. solaris 常用软件安装

    http://blog.csdn.net/cuterhei/article/category/1259722

  4. andriod 文本居中: android:gravity="center"

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...

  5. Xcode插件管理器Alcatraz的使用

    Xcode插件管理器Alcatraz的使用 下载地址 https://github.com/alcatraz/Alcatraz 下载软件包 解压以及编译 重启Xode并Load Bundle 安装插件 ...

  6. [翻译] 学习iOS开发的建议:如何从菜鸟到专家

    [文章原地址] http://mobile.tutsplus.com/tutorials/iphone/ios-quick-tip-from-novice-to-expert/ 翻译有误之处请勿见笑, ...

  7. 偏执却管用的10条Java编程技巧

    本文由 ImportNew - LynnShaw 翻译自 javacodegeeks.欢迎加入翻译小组.转载请见文末要求. 经过一段时间的编码(咦,我已经经历了将近20年的编程生涯,快乐的日子总是过得 ...

  8. 在oracle中查询已知表名的表中所有字段名,每个字段是否是主键,是否是外键,是否为空的sql语句

    查询表的所有列及其属性:select t.*,c.COMMENTS from user_tab_columns t,user_col_comments c where t.table_name = c ...

  9. Python的开源人脸识别库:离线识别率高达99.38%

    Python的开源人脸识别库:离线识别率高达99.38%   github源码:https://github.com/ageitgey/face_recognition#face-recognitio ...

  10. CoreAudio实现录音播音和扬声器听筒模式的切换

    本例子使用Core Audio实现类似于微信的音频对讲功能,可以录音和播放并且实现了听筒模式和扬声器模式的切换.录音主要使用AVAudioRecorder类来实现录音功能,播放则使用AVAudioPl ...