GuGuFishtion

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1699    Accepted Submission(s): 627

Problem Description
Today XianYu is too busy with his homework, but the boring GuGu is still disturbing him!!!!!!
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:

Gu(a,b)=ϕ(ab)ϕ(a)ϕ(b)

And now you, the xxxxxxx little guy, have to solve the problem below given m,n,p.’

(∑a=1m∑b=1nGu(a,b))(modp)

So SMART and KINDHEARTED you are, so could you please help GuGu to solve this problem?
‘GU GU!’ GuGu thanks.

 
Input
Input contains an integer T indicating the number of cases, followed by T lines. Each line contains three integers m,n,p as described above.
1≤T≤3
1≤m,n≤1,000,000
max(m,n)<p≤1,000,000,007
And given p is a prime.
 
Output
Please output exactly T lines and each line contains only one integer representing the answer.
 
Sample Input
1
5 7 23
 
Sample Output
2
解析  我们容易得到 g(a,b)=ϕ(ab)/ϕ(a)ϕ(b)=gcd(a,b)/ϕ(gcd(a,b)
1-n,1-m的 gcd最多有min(n,m)个所以转换成求1-n,1-m中gcd(a,b)=k,k的出现次数.
AC代码
#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的更多相关文章

  1. hdu 6390 欧拉函数+容斥(莫比乌斯函数) GuGuFishtion

    http://acm.hdu.edu.cn/showproblem.php?pid=6390 题意:求一个式子 题解:看题解,写代码 第一行就看不出来,后面的sigma公式也不会化简.mobius也不 ...

  2. GuGuFishtion HDU - 6390 (杭电多校7E)

    啊啊啊啊...全在纸上 字丑...算了算了 然后除法部分都用逆元就好了 还有逆元打表....学到了...牛逼 #include<map> #include<set> #incl ...

  3. HDU 6390 GuGuFishtion

    题意: 计算: \[\sum\limits_{a = 1}^{m}\sum\limits_{b = 1}^{n} \frac{\varphi(ab)}{\varphi(a)\varphi(b)} (\ ...

  4. GuGuFishtion HDU - 6390 (欧拉函数,容斥)

    GuGuFishtion \[ Time Limit: 1500 ms\quad Memory Limit: 65536 kB \] 题意 给出定义\(Gu(a, b) = \frac{\phi(ab ...

  5. HDU 6390 GuGuFishtion(莫比乌斯反演 + 欧拉函数性质 + 积性函数)题解

    题意: 给定\(n,m,p\),求 \[\sum_{a=1}^n\sum_{b=1}^m\frac{\varphi(ab)}{\varphi(a)\varphi(b)}\mod p \] 思路: 由欧 ...

  6. hdu GuGuFishtion 6390 数论 欧拉函数

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=6390 直接开始证明: 我们设…………………………………….....…...............………… ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. Tomcat配置Oracle数据源

    开发环境:Eclipse luna.tomcat 7.Oracle 配置Oracle datasource步骤 第一步:打开tomcat目录下的 context.xml 文件,添加 Resource ...

  2. Python 中列表、元祖、字典

    1.元祖: 对象有序排列,通过索引读取读取, 对象不可变,可以是数字.字符串.列表.字典.其他元祖 2.列表: 对象有序排列,通过索引读取读取, 对象是可变的,可以是数字.字符串.元祖.其他列表.字典 ...

  3. Linux之基础命令——文件搜索

    grep(匹配符合条件的字符串) 无参:显示匹配行 -c:显示匹配行数 -e 字符串:匹配特殊字符串,如-开头 -i:忽略大小写 -v:输出不匹配行 -w:匹配指定字符串 可以和别的命令通过" ...

  4. uva10366 Faucet Flow

    每次找到两边离中心最高的板,如果等,再找外围的最高版...画图便于理解两边先找到距离(-1,1)最近的最大值L和R,因为可能存在多个最高的挡板.接着比较两个L和R的大小,相等的话分别分析两边,取最小值 ...

  5. Microsoft Windows Server DHCP

    Microsoft Windows Server DHCP DHCP IP地址第一个来源是DHCP服务器,第二个来源是PPP点对点协议(ADSL为PPPOE);DHCP是Dynamic Host Co ...

  6. JavaSE-28 hashCode()方法、equals()方法和==相关概念

    概述 Java中,Object类是所有类的基类:如果一个类没有明确继承其他已定义的类,则默认继承Object类. Object类提供了以下方法,对于其他方法,请参考前期专题描述. hashCode() ...

  7. delphi jinchengneicun

    http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Configuring_the_Memory_Manager https://docs.micros ...

  8. HTTP初步了解

    HTTP协议简介 HTTP(超文本传输协议)是应用层上的一种客户端/服务端模型的通信协议,它由请求和响应构成,且是无状态的.(暂不介绍HTTP2) 协议 协议规定了通信双方必须遵循的数据传输格式,这样 ...

  9. JS第三方中间件的延伸

    js中间件 当我们在编写业务代码时候,我们无法避免有些业务逻辑复杂而导致业务代码写得又长又乱,如果再加上时间紧凑情况下写出来的代码估计会更让人抓狂.以至于我们一直在寻求更好的架构设计和更好的代码设计, ...

  10. Maven实战读书笔记(四):Maven生命周期与插件

    Maven的生命周期是对所有构建过程的抽象和统一.包含了项目的清理.初始化.编译.测试.打包.集成测试.验证.部署和站点生成等几乎所有构建步骤. Maven的生命周期是抽象的,其实际行为是由插件来完成 ...