hdu4059---The Boss on Mars(容斥原理+前n项的4次方和)
来源:互联网 发布:氟硝西泮片淘宝店 编辑:程序博客网 时间:2024/05/01 17:40
Problem Description
On Mars, there is a huge company called ACM (A huge Company on Mars), and it’s owned by a younger boss.
Due to no moons around Mars, the employees can only get the salaries per-year. There are n employees in ACM, and it’s time for them to get salaries from their boss. All employees are numbered from 1 to n. With the unknown reasons, if the employee’s work number is k, he can get k^4 Mars dollars this year. So the employees working for the ACM are very rich.
Because the number of employees is so large that the boss of ACM must distribute too much money, he wants to fire the people whose work number is co-prime with n next year. Now the boss wants to know how much he will save after the dismissal.
Input
The first line contains an integer T indicating the number of test cases. (1 ≤ T ≤ 1000) Each test case, there is only one integer n, indicating the number of employees in ACM. (1 ≤ n ≤ 10^8)
Output
For each test case, output an integer indicating the money the boss can save. Because the answer is so large, please module the answer with 1,000,000,007.
Sample Input
2
4
5
Sample Output
82
354
Hint
Case1: sum=1+3*3*3*3=82
Case2: sum=1+2*2*2*2+3*3*3*3+4*4*4*4=354
Author
ZHANG, Chao
Source
2011 Asia Dalian Regional Contest
Recommend
首先考虑n的素因子,然后统计可以用容斥
求
公式是:
由于要取模,所以要用下逆元
/************************************************************************* > File Name: hdu4059.cpp > Author: ALex > Mail: zchao1995@gmail.com > Created Time: 2015年05月28日 星期四 16时49分35秒 ************************************************************************/#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <queue>#include <stack>#include <map>#include <bitset>#include <set>#include <vector>using namespace std;const double pi = acos(-1.0);const int inf = 0x3f3f3f3f;const double eps = 1e-15;typedef long long LL;typedef pair <int, int> PLL;vector <int> mst;const int mod = 1000000007;LL calc(LL n) { LL ans = 0; LL A = 6LL; for (int i = 1; i <= 5; ++i) { A *= n; A %= mod; } ans += A; A = 15LL; for (int i = 1; i <= 4; ++i) { A *= n; A %= mod; } ans += A; A = 10LL; for (int i = 1; i <= 3; ++i) { A *= n; A %= mod; } ans += A; ans -= n; ans = (ans % mod + mod) % mod; ans *= (233333335LL % mod); ans %= mod; return ans;}int main() { int t; scanf("%d", &t); while (t--) { LL n, m; scanf("%lld", &n); m = n; mst.clear(); for (int i = 2; i * i <= n; ++i) { if (n % i == 0) { mst.push_back(i); while (n % i == 0) { n /= i; } } } if (n > 1) { mst.push_back(n); } LL ans = calc(m); LL C = 0; int size = mst.size(); for (int i = 1; i < (1 << size); ++i) { int bits = 0; int num = 1; for (int j = 0; j < size; ++j) { if (i & (1 << j)) { ++bits; num *= mst[j]; } } int k = m / num; LL tmp = num; tmp *= num; tmp %= mod; tmp *= num; tmp %= mod; tmp *= num; tmp %= mod; tmp *= calc((LL)k); tmp %= mod; if (bits & 1) { C += tmp; } else { C -= tmp; } C = (C % mod + mod) % mod; } ans -= C; ans = (ans % mod + mod) % mod; printf("%lld\n", ans); } return 0;}
- hdu4059---The Boss on Mars(容斥原理+前n项的4次方和)
- hdu4059 The Boss on Mars(差分+容斥原理)
- hdu4059 The Boss on Mars(容斥)
- HDU4059 The Boss on Mars【容斥原理】【乘法逆元】【高次求和】
- HDU 4059 The Boss on Mars 解题报告(4次方和+质因子分解+逆元+容斥原理)
- hdu4059 The Boss on Mars
- The Boss on Mars(容斥原理)
- HDU 4059 The Boss on Mars(容斥原理)
- zoj 3547 - 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(容斥原理)
- hdu4059The Boss on Mars 容斥原理
- hdu 4059 The Boss on Mars 容斥原理 数列通项公式
- Python Dict -> Object
- 微信第三方网站登录
- MySQL 5.6在Windows下免安装版配置
- jdbc基础 (三) 大文本、二进制数据处理
- springmvc 配置
- hdu4059---The Boss on Mars(容斥原理+前n项的4次方和)
- JAVA操作properties文件
- 使用Gradle打Android渠道包
- Stanford机器学习---第一讲. Linear Regression with one variable
- Hello Java!
- 遇见C++ Lambda
- 用angularjs 模块时Error: [ng:areq] Argument 'controller' is not a function,
- 用友ERT T6 技术解析(二) --WCF发布
- Navicat Premium下sql导入中文乱码解决方案