The Boss on Mars
The Boss on Mars
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2327 Accepted Submission(s):
718
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.
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)
money the boss can save. Because the answer is so large, please module the
answer with 1,000,000,007.
4
5
354
Case1: sum=1+3*3*3*3=82
Case2: sum=1+2*2*2*2+3*3*3*3+4*4*4*4=354
http:
//acm.hdu.edu.cn/showproblem.php?pid=4059
///这题主要是公式问题,然后稍微对容斥原理计算个数,改为mult的特殊利用即可;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
///1~n这n个数的4次方和:n*(n+1)*(6*n*n*n+9*n*n+n-1)/30; 这里百度的公式;
typedef long long ll;
const ll N = 1e6+5;
const ll mod = 1e9+7;
ll n, ans;
ll get4mult(ll mult)
{
return
mult*mult%mod*mult%mod*mult%mod;
}
ll extgcd(ll a,ll b,ll &x,ll &y)
{
if
(b==0){
x = 1, y = 0;
return
a;
}
ll d = extgcd(b,a%b,x,y);
ll t = x;
x = y;
y = t-a/b*y;
return
d;
}
ll inverse(ll t)
{
ll x, y;
ll d = extgcd(t,mod,x,y);
return
(x%mod+mod)%mod;
}
ll calu(ll n)
{
return
n*(n+1)%mod*(6*n*n%mod*n%mod+9*n*n%mod+n-1)%mod*inverse(30)%mod;
}
ll rongchi(ll n)
{
ll m = n;
vector<ll> v;
for
(ll i = 2; i*i <= m; i++){
if
(m%i==0){
v.push_back(i);
while
(m%i==0) m/=i;
}
}
if
(m>1) v.push_back(m);
ll len = v.size();
for
(ll i = 1; i < (1<<len); i++){
ll mult = 1, ones = 0;
for
(ll j = 0; j < len; j++){
if
(i&(1<<j)){
ones++;
mult = mult*v[j];
}
}
if
(ones%2) {
/// 变成了 - 因为假设是原来的容斥,那么cnt指的是不互质的个数,是要被剪掉的;
///而本题:也是要减掉,但是不是计算个数,而是对每一个过程有作用,减去:减变为了加,加变为了减;
ans = ans-get4mult(mult)*calu(n/mult);
ans = (ans%mod+mod)%mod;
}
else
/// 变成了 +
{
ans = ans+get4mult(mult)*calu(n/mult);
ans = (ans%mod+mod)%mod;
}
}
v.clear();
return
ans;
}
int main()
{
ll T;
cin>>T;
while
(T--)
{
cin>>n;
ans = calu(n);
printf(
"%lld\n"
,rongchi(n));
}
return
0;
}
The Boss on Mars的更多相关文章
- hdu4059 The Boss on Mars(差分+容斥原理)
题意: 求小于n (1 ≤ n ≤ 10^8)的数中,与n互质的数的四次方和. 知识点: 差分: 一阶差分: 设 则 为一阶差分. 二阶差分: n阶差分: 且可推出 性质: 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) ...
- hdu4059 The Boss on Mars
The Boss on Mars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4059 The Boss on Mars(容斥原理 + 四次方求和)
传送门 The Boss on Mars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 数论 + 容斥 - HDU 4059 The Boss on Mars
The Boss on Mars Problem's Link Mean: 给定一个整数n,求1~n中所有与n互质的数的四次方的和.(1<=n<=1e8) analyse: 看似简单,倘若 ...
- HDU 4059 The Boss on Mars(容斥原理)
The Boss on Mars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4059 The Boss on Mars
The Boss on Mars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 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 ...
- zoj 3547 The Boss on Mars
需要用到概率论的容斥定理以及计算1 ^ 4 + 2 ^ 4 + ……+ n ^ 4的计算公式1^4+2^4+……+n^4=n(n+1)(2n+1)(3n^2+3n-1)/30 #pragma comm ...
随机推荐
- C# 秒数转日期_由秒数得到日期几天几小时_当前日期时间,转换为秒
///<summary> ///由秒数得到日期几天几小时... ///</summary ///<param name="t">秒数</para ...
- 向项目中添加dtd文件实现代码提示
我们在编辑代码的过程中,有代码提示的编辑工具总是受到青睐. 本文将讲解怎么在eclipse中加入dtd文件实现代码提示.myeclipse同理 选择window,选择perferences,然后拉到下 ...
- 帮助自定义选择框样式的Javascript - DropKick.js
来源:GBin1.com 在线演示 在线下载 当你想要设计一个页面样式时,没有什么比表单更让人头疼了.而当你设计一个表单的样式时,最让你头疼的就应该非下拉框<select>莫属了. 我们 ...
- iOS 8 Share Extension Safari URL Example(在iOS中分享url的样例)
ios8 的Extension给我们提供了非常多奇妙的功能.以后分享内容再也不用进入app了,让我们的手机更安全,以下我们以在safari 浏览器中分享一个web url 来讲述Share Exten ...
- iOS 证书管理.p12文件不能导出
iOS证书不能导出p12文件: 首先要确认证书是从你这个电脑上制作生成的! 钥匙串-->我的证书--->右键,就可以导出了!
- Android蓝牙音乐获取歌曲信息
由于我在蓝牙开发方面没有多少经验,如果只是获取一下蓝牙设备名称和连接状态那么前面的那篇文章就已经足够了,接下来的内容是转自一个在蓝牙音乐方面颇有经验的开发者的博客,他的这篇文章对我帮助很大. 今天,先 ...
- 网站缓存技术(Redis、Memcached、Ehcache)
Redis 是什么? 通常而言目前的数据库分类有几种,包括 SQL/NSQL,,关系数据库,键值数据库等等等. 分类的标准也不一,Redis本质上也是一种键值数据库的,但它在保持键值数据库简单快捷特点 ...
- spring中的AOP 以及各种通知 配置
理解了前面动态代理对象的原理之后,其实还是有很多不足之处,因为如果在项目中有20多个类,每个类有100多个方法都需要判断是不是要开事务,那么方法调用那里会相当麻烦. spring中的AOP很好地解决了 ...
- Workshop:用Python做科学计算
Python是程序史上最流行的开源语言之一. 仅在官方包索引PyPi上就已经发布了超过10万个开源软件包,而且还有更多的项目. 在SciPy的麾下,有一个成熟的python包生态系统,可以使用Pyth ...
- Ant + ivy的安装
有了Ivy的帮忙,我们不需要为了一个库依赖管理而舍弃Ant去学那个难搞的Maven了. 基本配置步骤如下: 1.copy Ivy插件到ant_home/lib下: ivy安装 简单的安装方法: 直 ...