HDU 6390
GuGuFishtion
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1699 Accepted Submission(s): 627
At the break time, an evil idea arises in XianYu's mind.
‘Come on, you xxxxxxx little guy.’
‘I will give you a function ϕ(x) which counts the positive integers up to x that are relatively prime to x.’
‘And now I give you a fishtion, which named GuGu Fishtion, in memory of a great guy named XianYu and a disturbing and pitiful guy GuGu who will be cooked without solving my problem in 5 hours.’
‘The given fishtion is defined as follow:
And now you, the xxxxxxx little guy, have to solve the problem below given m,n,p.’
So SMART and KINDHEARTED you are, so could you please help GuGu to solve this problem?
‘GU GU!’ GuGu thanks.
1≤T≤3
1≤m,n≤1,000,000
max(m,n)<p≤1,000,000,007
And given p is a prime.
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define huan printf("\n")
#define debug(a,b) cout<<a<<" "<<b<<" "<<endl
#define ffread(a) fastIO::read(a)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+,inf=0x3f3f3f3f;
int check[maxn],phi[maxn],prime[maxn];
ll inv[maxn],f[maxn];
void philist()
{
int cnt=;
phi[]=;
for(int i=; i<=maxn; i++)
{
if(!check[i])
{
prime[++cnt]=i;
phi[i]=i-;
}
for(int j=; j<=cnt&&prime[j]*i<=maxn; j++)
{
check[i*prime[j]]=;
if(i%prime[j])
phi[i*prime[j]]=phi[i]*(prime[j]-);
else
{
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
}
}
}
void init(int mod,int n)
{
fillchar(f,);
inv[]=;
for(int i=;i<=n;i++)
inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
}
int main()
{
int t,n,m,p;
scanf("%d",&t);
philist();
while(t--)
{
scanf("%d%d%d",&n,&m,&p);
ll ans=;
if(n>m)
swap(n,m);
init(p,n);
for(ll i=n;i>=;i--) //容斥求1-n,1-m中gcd为i的个数
{
f[i]=(ll)(n/i)*(m/i);
for(int j=i+i; j<=n; j+=i) //f[i]表示gcd为i的对数有f[i]个
f[i]=f[i]-f[j];
ans=(ans+f[i]%p*i%p*inv[phi[i]])%p;
}
printf("%lld\n",ans);
}
}
HDU 6390的更多相关文章
- hdu 6390 欧拉函数+容斥(莫比乌斯函数) GuGuFishtion
http://acm.hdu.edu.cn/showproblem.php?pid=6390 题意:求一个式子 题解:看题解,写代码 第一行就看不出来,后面的sigma公式也不会化简.mobius也不 ...
- GuGuFishtion HDU - 6390 (杭电多校7E)
啊啊啊啊...全在纸上 字丑...算了算了 然后除法部分都用逆元就好了 还有逆元打表....学到了...牛逼 #include<map> #include<set> #incl ...
- HDU 6390 GuGuFishtion
题意: 计算: \[\sum\limits_{a = 1}^{m}\sum\limits_{b = 1}^{n} \frac{\varphi(ab)}{\varphi(a)\varphi(b)} (\ ...
- GuGuFishtion HDU - 6390 (欧拉函数,容斥)
GuGuFishtion \[ Time Limit: 1500 ms\quad Memory Limit: 65536 kB \] 题意 给出定义\(Gu(a, b) = \frac{\phi(ab ...
- HDU 6390 GuGuFishtion(莫比乌斯反演 + 欧拉函数性质 + 积性函数)题解
题意: 给定\(n,m,p\),求 \[\sum_{a=1}^n\sum_{b=1}^m\frac{\varphi(ab)}{\varphi(a)\varphi(b)}\mod p \] 思路: 由欧 ...
- hdu GuGuFishtion 6390 数论 欧拉函数
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6390 直接开始证明: 我们设…………………………………….....…...............………… ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
随机推荐
- jq获取设置选中值
var standard = $('input[name="standard"]:checked').val(); $("input[name='advertByid'] ...
- 原创 齐天大圣老司机亲传rescue恢复磁盘分区
老葵花哥哥课堂开课了本文档秉承爱看不看的原则 一不要钱 二服务大众的高尚情操咱们今天讲一讲rescue恢复磁盘分区 首先咱们搭建环境搞起来 (parted) mkpart #创建分区 Partitio ...
- SQLite – GROUP BY
SQLite - GROUP BY SQLite GROUP BY子句中使用与SELECT语句的合作安排相同的数据组. 在GROUP BY子句之前一个SELECT语句的WHERE子句,先于ORDER ...
- System.currentTimeMillis()与日期之间的相互转换
System.currentTimeMillis()与日期 之间是可以相互转换的,大多数Android开发者都知道 通过 SimpleDateFormat dateformat = new Simpl ...
- (转)SpringMVC学习(九)——SpringMVC中实现文件上传
http://blog.csdn.net/yerenyuan_pku/article/details/72511975 这一篇博文主要来总结下SpringMVC中实现文件上传的步骤.但这里我只讲单个文 ...
- 事件冒泡 & 阻止事件冒泡
事件冒泡 : 当一个元素接收到事件的时候,会把他接收到的所有传播给他的父级,一直到顶层window.事件冒泡机制 阻止冒泡 : 当前要阻止冒泡的事件函数中调用 event.cancelBubble = ...
- 解决Invalid bound statement (not found)(Mybatis的Mapper绑定问题)
一.问题描述 使用mybatis的项目在本地可以正常运行,但当使用maven或Jenkins打包部署到服务器上时出现了绑定错误,异常信息为: org.apache.ibatis.binding.Bin ...
- xshell全局设置配色方案
新建XTerm1.xcs文件,将以下内容黏贴进去,保存退出 [XTerm] text=839496 cyan(bold)=93a1a1 text(bold)=408080 magenta=dd3682 ...
- 896. Monotonic Array@python
An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is mono ...
- 01Ping程序的设计
1.Ping程序设计具体设计任务 1.1 实验目的 PING程序是我们使用的比较多的用于测试网络连通性的程序.PING程序基于ICMP,使用ICMP的回送请求和回送应答来工作.由计算机网络课程知道,I ...