Codeforces 1295D Same GCDs
题目链接
[link](CF1295D Same GCDs)
Solution
这是一道结论题,有两个做法,分别用了欧拉函数或一点点莫比乌斯反演
(这里只放欧拉函数的做法)
设\(d=gcd(m,a)\)
\]
从互质的关系入手进行考虑
所以答案就是\(\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的更多相关文章
- 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)= ...
- Educational Codeforces Round 81 (Rated for Div. 2) A-E简要题解
链接:https://codeforces.com/contest/1295 A. Display The Number 贪心思路,尽可能放置更多位,如果n为奇数,消耗3去放置一个7,剩下的放1 AC ...
- Educational Codeforces Round 81 + Gym 102267
UPD:变色了!!!历史最高1618~ Educational Codeforces Round 81 (Rated for Div. 2) The 2019 University of Jordan ...
- Codeforces题解集 1.0
记录 Codeforces 2019年12月19日到 2020年2月12日 的部分比赛题 Educational Codeforces Round 82 (Rated for Div. 2) D Fi ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
随机推荐
- k8s资源pod yaml文件分析
apiVersion: v1 kind: Pod_name metadata name: pod_name #描述Pod的名字 namespace: default #描述Pod所在命名空间,如果不设 ...
- Mac电脑如何彻底删除node
之前本来想搭建一个hexo来写博客的,但是最后还是放弃,老老实实就在博客园和CSDN写博文了,这里记录一下怎么在Mac电脑下彻底删除node.js的方法 下面这个方法是我结合了网上好几个方法综合在一起 ...
- 编写注册表.reg文件
Windows 中的注册表文件( system.dat 和 user.dat )是 Windows 的核心数据库,因此,对 Windows 来说是非常重要的. 通过修改注册表文件中的数据,可以达到优化 ...
- NiFi_Demo_调度示例
1.背景 要求:每天凌晨1:00后开始每2min执行一次sql查询 2.作业编排 3.各模块配置 3.1 GenerateFlowFile 作用:用于产生flowfile,该flowfile内容为空. ...
- UML-状态机图和建模
1.目标:如何画状态机图 2.定义:描述某个对象的状态.感兴趣的事件.以及对象响应该事件的行为. 转换:用箭头表示 状态:用圆角矩形表示 事件:指的是一件值得注意的事情的发生.如:拿起电话. 当事件“ ...
- TCP_Wrappers简介
转载自:http://www.cnblogs.com/duzhaoqi/ TCP_Wrappers 简介 TCP_Wrappers是一个工作在第四层(传输层)的的安全工具,对有状态连接的特定服 ...
- Java集合(一)——Collection
集合概述 集合(Collections)是存储对象的容器.方便对多个对象的操作.存储对象,集合的作用就在这时显现了. 集合的出现就是为了持有对象.集合中可以存储任意类型的对象, 而且长度可变.在程序中 ...
- springboot跨域请求接口示例
一.项目架构 二.项目内容 1.GlobalCrosConfig.java package com.config; import org.springframework.context.annotat ...
- 更改php.ini配置
vi /etc/php.ini #编辑修改 @ini_set('memory_limit', '64M'); / ...
- vue图片查看器
vue 安装图片查看器插件安装cnpm install v-viewer引用 import 'viewerjs/dist/viewer.css' import Viewer from 'v-viewe ...