HDU 4059 The Boss on Mars(容斥原理)
来源:互联网 发布:刷信誉源码平台 编辑:程序博客网 时间:2024/04/27 17:04
容斥原理,先把 n 质分解,利用x^4 的前n项和公式,然后把与 n 不互质的数的和求出来然后减一下就可以了。
#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<vector>#include<cmath>#define LL long long#define CLR(a, b) memset(a, b, sizeof(a))using namespace std;const int N = 100000001;const int M = 11111;const int MOD = 1e9 + 7;vector<LL> hav;bool isp[M];int p[M], cnt, sz;LL n;void getp(){ CLR(isp, 0); int i, j;cnt = 0; isp[0] = isp[1] = 1; for(i = 2; i < M; i ++) { if(!isp[i]) { p[cnt ++] = i; if(i <= 1111)for(j = i * i; j < M; j += i) isp[j] = 1; } }}void get_hav(LL h){ LL i; hav.clear(); for(i = 0; i < cnt && h > 1; i ++) { if(h % p[i] == 0) { h /= p[i]; int s = hav.size(); if( s == 0 || hav[s - 1] != p[i])hav.push_back(p[i]); i --; } } if(h != 1) hav.push_back(h);}LL inv(LL x){ LL r, y; for(r = 1, y = MOD - 2; y; x = x * x % MOD, y >>= 1) (y & 1) && (r = r * x % MOD); return r;}LL get_sum(LL n){ LL ret; ret = n * (2 * n + 1) % MOD * (n + 1) % MOD * ((3 * n * (n + 1) - 1) % MOD) % MOD * inv(30) % MOD; return ret;}LL F_pow(LL a, LL b){ LL ret = 1; while(b) { if(b & 1) ret = ret * a % MOD; a = a * a % MOD; b >>= 1; } return ret;}LL dfs(LL u, LL c){ LL i, j; LL ret = 0; for(i = u; i < sz; i ++) { ret = (ret + F_pow(hav[i] * c, 4) * get_sum(n / hav[i] / c) % MOD - dfs(i + 1, c * hav[i])) % MOD; } return (ret + MOD) % MOD;}int main(){ //freopen("input.txt", "r", stdin); LL i, j, t; getp(); cin >> t; while(t --) { cin >> n; get_hav(n); sz = hav.size(); cout << (get_sum(n) - dfs(0, 1) + MOD) % MOD << endl; }}
- HDU 4059 The Boss on Mars(容斥原理)
- hdu 4059 The Boss on Mars(容斥原理)
- HDU 4059 The Boss on Mars(容斥原理)
- hdu 4059 The Boss on Mars(容斥原理)
- HDU 4059 The Boss on Mars【容斥原理】
- hdu 4059 The Boss on Mars 容斥原理
- HDU 4059 The Boss on Mars ( 容斥原理)
- HDU 4059 The Boss on Mars(容斥原理)
- 数论(容斥原理)hdu-4059-The Boss on Mars
- HDU 4059 The Boss on Mars(容斥原理+四次方数列求和)
- The Boss on Mars(容斥原理)
- HDU 4059 The Boss on Mars-矩阵+容斥
- hdu 4059 The Boss on Mars(容斥)
- HDU 4059 The Boss on Mars(质数分解+容斥)
- hdu 4059 The Boss on Mars 容斥原理 数列通项公式
- HDU 4059 The Boss on Mars 容斥原理+逆元
- HDU 4059 The Boss on Mars(容斥原理 + 四次方求和)
- HDU 4059 The Boss on Mars【容斥原理+逆元】
- 时间系统、进程的调度与切换
- static
- 今天是个好天气啊,但是心情不好
- Mat
- easymock教程-easymock的典型使用
- HDU 4059 The Boss on Mars(容斥原理)
- C++指针的管理
- 编程珠玑之第一章习题7:处理程序存在的缺陷的问答与测试
- poj 2417 Discrete Logging 求解模方程a^x=b(mod n),n为素数+模板题(baby_step giant_step)
- android整合--notification推送通知
- SSH学习笔记二
- Java--chapter03--输出希腊字母
- 函数调用机制与调用约定(转载)
- opengl片段测试之后的逻辑操作