需要用到概率论的容斥定理以及计算1 ^ 4 + 2 ^ 4 + ……+ n ^ 4的计算公式1^4+2^4+……+n^4=n(n+1)(2n+1)(3n^2+3n-1)/30

#pragma comment(linker,"/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath> #define LL long long
const LL mod = 1e9 + 7;
#define MAX 10000 int len, prime[MAX], num[30];
bool vis[MAX + 5];
LL n, sum, pi; void get_prime(){
len = 0;
for(int i = 2; i<=MAX; ++i){
if(!vis[i]) prime[len++] = i;
for(int j = i * i; j <= MAX; j+=i) vis[j] = 1;
}
} LL power(LL x, LL y){
if(y == 0) return 1;
if(y == 1) return x;
LL v = power(x, y / 2);
v = v * v % mod;
if(y % 2 == 1) v = v * x % mod;
return v;
} LL cal(LL v){
return v * (v + 1) % mod * (v * 2 + 1) % mod * (v * v * 3 % mod + v * 3 - 1 + mod) % mod * pi % mod;
} void dfs(int cnt, int p, int pos, LL s){
if(cnt % 2 == 1) sum = (sum + cal(n / s) * s % mod * s % mod * s % mod * s % mod) % mod;
else sum = (sum - cal(n / s) * s % mod * s % mod * s % mod * s % mod + mod) % mod;
for(int i = pos; i < p; ++i)
dfs(cnt + 1, p, i + 1, s * num[i] % mod);
} int main ()
{
//freopen ("in.txt", "r", stdin);
get_prime();
//for(int i = 0; i < len; ++i) printf("%d ", prime[i]);
pi = power(30, mod - 2);
int t;
scanf ("%d", &t);
while (t--)
{
int x, p = 0;
scanf("%d", &x);
n = x;
sum = cal(n);
//printf("%d\n", n);
for(int i = 0; i < len; ++i){
int v = prime[i];
if(v > x) break;
if(x % v == 0) num[p++] = v;
while(x % v ==0) x /= v;
}
if(x > 1) num[p++] = x;
//for(int i = 0; i < p; ++i) printf("%d ", num[i]);
for (int i = 0; i < p; ++i)
dfs(0, p, i + 1, (LL)num[i]);
printf("%lld\n", sum);
}
return 0;
}

zoj 3547 The Boss on Mars的更多相关文章

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

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

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

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

  3. hdu4059 The Boss on Mars

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

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

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

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

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

  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. hdu 4059 The Boss on Mars

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

  9. 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 ...

随机推荐

  1. php增删改查,自己写的demo

    1.链接数据库通用方法:conn.php <?php //第一步:链接数据库 $conn=@mysql_connect("localhost:3306","root ...

  2. SOAP 简单对象访问协议

    webService三要素 SOAP.WSDL(WebServicesDescriptionLanguage).UDDI(UniversalDescriptionDiscovery andIntegr ...

  3. BitmapFactory 加载图片到内存

    Bitmap占用内存分析 Android的虚拟机是基于寄存器的Dalvik,它的最大堆(单个进程可用内存)大小一般是16M,当然不同设备是不一样的,可以查看/system/build.prop文件,[ ...

  4. 网页JavaScript2

    window.close()     关闭网页, window.opener.close()    关闭打开当前窗口的源窗口 间隔与延迟 window.setlnterval("执行代码&q ...

  5. django: db - many to many

    本讲介绍数据库多对多关系,代码样例继前文使用. 一,在 blog/models.py 中创建对象: # Many-To-Many Example : Authors vs Books class Au ...

  6. 使用VS Code开发TypeScript--定义变量推荐使用let

    使用VS Code开发TypeScript--定义变量推荐使用let 目录 作用域规则 JavaScript的严格模式 let与var的区别 作用域规则 一直以来我们都是通过var关键字定义JavaS ...

  7. eclipse中安装genymotion

    在eclipse中安装genymotion.安装genymotion需要先安装virtualbox.选择Help选项中的install new software 然后点击进去点击ADD,在locati ...

  8. Caesar cipher

    #include <iostream> using namespace std; int main() {int k,i; char s[5];  cin>>k;  for(; ...

  9. C#中睡眠函数Sleep

    命名空间:using System.Threading; Thread.Sleep();//睡眠500毫秒,也就是0.5秒

  10. log4Net使用的四个步骤

    第一步.引入程序集,并建立配置文件,放在根目录下config文件夹里.配置文件如下: <?xml version="1.0" encoding="utf-8&quo ...