hdu 4059 The Boss on Mars 容斥
求出ai^4+a2^4+......an^4的值, ai为小于n并与n互质的数。
用容斥做, 先求出1^4+2^4+n^4的和的通项公式, 显然是一个5次方程, 然后6个方程6个未知数, 我gauss消元解的(雾
然后筛出n所以的因子, 容斥就好。
容斥的时候, 每一个数的贡献是x^4 * getSum(x), getSum就是上面求出的通项公式。
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
vector <int> p;
ll pow(ll a, int b) {
ll ret = ;
while(b) {
if(b&)
ret = ret*a%mod;
a = a*a%mod;
b>>=;
}
return ret;
}
ll getsum(ll n) {
ll ret = *pow(n, )+*pow(n, )+*pow(n, )-n;
ret %= mod;
ll inv = pow(30LL, mod-)%mod;
return ret*inv%mod;
}
void getFactor(ll n) {
p.clear();
for(int i = ; i*i<=n; i++) {
if(n%i==) {
p.pb(i);
while(n%i==)
n/=i;
}
}
if(n>)
p.pb(n);
}
int main()
{
int t;
ll n;
cin>>t;
while(t--) {
cin>>n;
ll sum = getsum(n), d = ;
getFactor(n);
int num = p.size();
for(int i = ; i<(<<num); i++) {
ll multi = , one = ;
for(int j = ; j<num; j++) {
if((<<j)&i) {
one++;
multi = multi*p[j]%mod;
}
}
ll tmp = pow(multi, )%mod;
tmp*=getsum(n/multi);
tmp%=mod;
if(one&)
d += tmp;
else
d -= tmp;
d = (d+mod)%mod;
}
cout<<(sum-d+mod)%mod<<endl;
}
return ;
}
hdu 4059 The Boss on Mars 容斥的更多相关文章
- 数论 + 容斥 - 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) ...
- 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 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4059 The Boss on Mars(纳入和排除)
http://acm.hdu.edu.cn/showproblem.php?pid=4059 定义S = 1^4 + 2^4 + 3^4+.....+n^4.如今减去与n互质的数的4次方.问共降低了多 ...
- hdu 5792(树状数组,容斥) World is Exploding
hdu 5792 要找的无非就是一个上升的仅有两个的序列和一个下降的仅有两个的序列,按照容斥的思想,肯定就是所有的上升的乘以所有的下降的,然后再减去重复的情况. 先用树状数组求出lx[i](在第 i ...
- HDU 5794 A Simple Chess (容斥+DP+Lucas)
A Simple Chess 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5794 Description There is a n×m board ...
- HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
随机推荐
- Winform子窗体刷新父窗体
调用窗体(父):Form1,被调用窗体(子):Form2方法1: 所有权法//Form1://需要有一个公共的刷新方法public void Refresh_Method(){//...} ...
- _cdel stdcall
__cdecl 是C Declaration的缩写(declaration,声明),表示C语言默认的函数调用方法:所有参数从右到左依次入栈,这些参数由调用者清除,称为手动清栈.被调用函数不会要求调用者 ...
- 仿淘宝TAB切换搜索框
<div class="search"> <div id="searchBox"> <ul class="tab-bar ...
- Uber License for Android
Uber license for android list: 1.Butter Knife: 项目地址:https://github.com/JakeWharton/butterknife 这个开源库 ...
- distance.c
#include "stdio.h" #include "string.h" #include "math.h" #include &quo ...
- CSS左中右布局,规范案例
html部分 <body> <form id="form1" runat="server"> <div id="wrap ...
- 远程监控 – 应用程序运行状况测量 CSF 博客
在远程监控基础知识和故障排除中,我们探讨了 Windows Azure 平台提供的基础指标.信息源.工具和脚本,介绍了有关监控和应用程序运行状况的基本原则.我们演示了如何利用这些基本原则对在 Wind ...
- [Leetcode][Python]40: Combination Sum II
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 40: Combination Sum IIhttps://oj.leetco ...
- c++策略模式
这几天需要学习一下设计模式来为设计代码结构使得代码可扩展性强,代码更加易于维护,不用想很长时间也不知道怎么去设计一个工具的代码. 我的理解策略模式: 1.有一个策略基类,策略类是什么呢?策略类就是一个 ...
- 【每天一个Linux命令】13. Linux中whereis命令的用法
命令用途 whereis命令用来查找命令的位置,包括执行文件.源代码和手册页文件 命令用法 1. 查找指定命令<command>的位置,包括执行文件.源代码和手册页文件 格式:wher ...