题目链接

[link](CF1295D Same GCDs)

Solution

这是一道结论题,有两个做法,分别用了欧拉函数或一点点莫比乌斯反演

(这里只放欧拉函数的做法)

设\(d=gcd(m,a)\)

\[gcd(\frac{a}{d},\frac{m}{d})=gcd(\frac{x+a}{d},\frac{m}{d})=1
\]

从互质的关系入手进行考虑

所以答案就是\(\varphi(\frac{m}{d})\)

这个东西是可以在时限内求解的

CODE

#include<bits/stdc++.h>
using namespace std;
#define int long long
namespace yspm{
inline int read()
{
int res=0,f=1; char k;
while(!isdigit(k=getchar())) if(k=='-') f=-1;
while(isdigit(k)) res=res*10+k-'0',k=getchar();
return res*f;
}
inline void work()
{
int a=read(),m=read(),ans;
int gcd=__gcd(a,m); m/=gcd; ans=m;
for(int i=2;i*i<=m;++i)
{
if(m%i==0)
{
ans=ans/i*(i-1);
while(m%i==0) m/=i;
}
}
if(m>1) ans=ans/m*(m-1);
return cout<<ans<<endl,void();
}
signed main()
{
int T=read(); while(T--) work();
return 0;
}
}
signed main(){return yspm::main(); }

Codeforces 1295D Same GCDs的更多相关文章

  1. Educational Codeforces Round 81 (Rated for Div. 2) - D. Same GCDs(数学)

    题目链接:Same GCDs 题意:给你两个数$a$,$m(1 \leq a < m \leq 10^{10})$,求有多少个$x$满足:$0 \leq x < m$且$gcd(a,m)= ...

  2. Educational Codeforces Round 81 (Rated for Div. 2) A-E简要题解

    链接:https://codeforces.com/contest/1295 A. Display The Number 贪心思路,尽可能放置更多位,如果n为奇数,消耗3去放置一个7,剩下的放1 AC ...

  3. Educational Codeforces Round 81 + Gym 102267

    UPD:变色了!!!历史最高1618~ Educational Codeforces Round 81 (Rated for Div. 2) The 2019 University of Jordan ...

  4. Codeforces题解集 1.0

    记录 Codeforces 2019年12月19日到 2020年2月12日 的部分比赛题 Educational Codeforces Round 82 (Rated for Div. 2) D Fi ...

  5. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

随机推荐

  1. # vim ~/.vimrc vim配色

    Ubuntu # vim ~/.vimrc        # /hom/zzx 下 set nomodeline                "(这个一定要写,目前有这个安全漏洞) set ...

  2. 用Spring中的ResponseEntity文件批量压缩下载

    我看了很多网上的demo,先生成ZIP压缩文件,然后再下载. 我这里是生成ZIP文件流 进行下载.(核心代码没多少,就是一些业务代码) @RequestMapping(value = "/& ...

  3. Pytorch_torch.nn.MSELoss

    Pytorch_torch.nn.MSELoss 均方损失函数作用主要是求预测实例与真实实例之间的loss loss(xi,yi)=(xi−yi)2 函数需要输入两个tensor,类型统一设置为flo ...

  4. bugku-Web-多次(异或注入,判断被过滤的关键字)

    进去看到url感觉是sql注入, 加上',报错但是%23不报错,加上'--+,也不报错,说明可以用--+注释 加上' or 1=1--+,报错 尝试' oorr 1=1--+,正常 说明or被过滤了. ...

  5. 2,StructuredStreaming的事件时间和窗口操作

    推荐阅读:1,StructuredStreaming简介 使用Structured Streaming基于事件时间的滑动窗口的聚合操作是很简单的,很像分组聚合.在一个分组聚合操作中,聚合值被唯一保存在 ...

  6. POJ 1942:Paths on a Grid

    Paths on a Grid Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 22918   Accepted: 5651 ...

  7. 将list等分成n份

    public static <T> Map<Integer, List<T>> spiltList(List<T> list, int num) { M ...

  8. 2018.11.16javascript课上随笔(DOM)

    <li> <a href = "“#”>-</a> </li> <li>子节点:文本节点(回车),元素节点,文本节点. 不同节点树 ...

  9. JavaSE--for each

    参考:http://blog.csdn.net/yasi_xi/article/details/25482173 学习多线程的时候实例化线程数组而挖掘出来的一直以来的理解误区 之前一直以为for ea ...

  10. .NET 请求认证之access-token(oauth2.0与owin的结合)

    公司对外开放的接口,大多需要请求认证,如微信,阿里等.最近我刚好在搭建webapi框架.记录一下自己的理解. 一:请求认证的目的   之所以要对我们的接口进行请求认证,就是为了安全考虑的.以前都是在用 ...