Educational Codeforces Round 81 (Rated for Div. 2) D. Same GCDs 欧拉函数\莫比乌斯
传送门
文章目录
- 题意:
- 思路:
题意:
给定a,ma,ma,m,求满足gcd(a,m)=gcd(a+x,m)gcd(a,m)=gcd(a+x,m)gcd(a,m)=gcd(a+x,m)的xxx的个数,且0<=x<m0<=x<m0<=x<m。
思路:
由辗转相除法得:gcd(a+x,m)=gcd((a+x)modm,m)gcd(a+x,m)=gcd((a+x)\bmod m,m)gcd(a+x,m)=gcd((a+x)modm,m)
而(a+x)modm(a+x)\bmod m(a+x)modm正好是在[0,m−1][0,m-1][0,m−1]的数,与xxx范围吻合。考虑继续化简。
令gcd(a,m)=dgcd(a,m)=dgcd(a,m)=d,那么gcd((a+x)d,md)=gcd((a+x)modmd,md)=1gcd(\frac{(a+x)}{d},\frac{m}{d})=gcd(\frac{(a+x)\bmod m}{d},\frac{m}{d})=1gcd(d(a+x),dm)=gcd(d(a+x)modm,dm)=1
可知(a+x)modmd\frac{(a+x)\bmod m}{d}d(a+x)modm与md\frac{m}{d}dm互质。由于(a+x)modm<m(a+x)\bmod m<m(a+x)modm<m,对应xxx取值[0,m−1][0,m-1][0,m−1],答案即为与md\frac{m}{d}dm互质的数,即md\frac{m}{d}dm的欧拉函数。
当然也可以用莫比乌斯做,但是大材小用了。
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;LL a,m;int main()
{// ios::sync_with_stdio(false);
// cin.tie(0);int _; scanf("%d",&_);while(_--){scanf("%lld%lld",&a,&m);LL ans=m/__gcd(a,m);m/=__gcd(a,m);for(LL i=2;i<=m/i;i++)if(m%i==0){while(m%i==0) m/=i;ans=ans/i*(i-1);}if(m>1) ans=ans/m*(m-1);printf("%lld\n",ans);}return 0;
}
/**/
Educational Codeforces Round 81 (Rated for Div. 2) D. Same GCDs 欧拉函数\莫比乌斯相关推荐
- Educational Codeforces Round 81 (Rated for Div. 2) F.Good Contest \ 洛谷 划艇 组合 计数dp
cf传送门 P3643 [APIO2016]划艇 文章目录 题意: 思路: 题意: aia_iai在[li,ri][l_i,r_i][li,ri]等概率随机选一个数,求aaa数组不增的概率. 思 ...
- Educational Codeforces Round 81 (Rated for Div. 2) C. Obtain The String 序列自动机
传送门 文章目录 题意: 思路: 题意: 给你两个串s,ts,ts,t,每次可以取sss串的一个子序列,问你最少取多少次子序列,将这些子序列拼起来能得到ttt. 思路: 发现我题解里面没写过序列自动机 ...
- Educational Codeforces Round 81 (Rated for Div. 2) E. Permutation Separation 线段树 + dp
传送门 文章目录 题意: 思路: 题意: 给你一个打乱的排列,每个位置都各有一个价值,让你选择一个分界点,分成p1,p2,...,prp_1,p_2,...,p_rp1,p2,...,pr和pr ...
- Educational Codeforces Round 81 (Rated for Div. 2) B. Infinite Prefixes 数学
传送门 文章目录 题意: 思路: 题意: 给你个串sss,让后把它重复无限次得到ttt,定义前缀的价值为cnt0−cnt1cnt_0-cnt_1cnt0−cnt1,求ttt的前缀价值为xxx的前缀 ...
- Educational Codeforces Round 81 (Rated for Div. 2)
A题: 我们贪心按照位数大的拼就可以了. #include <bits/stdc++.h> using namespace std; int t,n; int main() {scanf( ...
- Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)
Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...
- Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...
- Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...
- Educational Codeforces Round 37 (Rated for Div. 2) 1
Educational Codeforces Round 37 (Rated for Div. 2) A.Water The Garden 题意:Max想给花园浇水.花园可被视为长度为n的花园床,花园 ...
最新文章
- YbtOJ#631-次短路径【左偏树,最短路】
- [剑指offer][JAVA][面试题第13题][机器人的运动][DFS][BFS]
- msbuild构建时用SVN修改版本号代替AssemblyVersion的Revision版本号
- 圆括号匹配c语言代码,求救!!一道关于表达式圆括号匹配的经典题目
- python 面试题(3)--- 进制转换
- redis 消息队列 过段时间不能下发_以Redis来谈消息队列
- jQuery选择器遇上一些特殊字符
- Halcon PDF文档(hdevelop_users_guide)学习总结之六——Halcon如何导出C++代码
- 2021年宇华实验中学高考成绩查询,2021年河南高考状元多少分,今年河南高考状元资料名单...
- IBM核心软件如何应对“互联网+”的技术挑战
- 五、肺癌检测-数据集训练 training.py model.py
- Cisco ❀ QinQ技术与VXLAN技术的区别
- 微信卡包系列-添加微信卡券优惠券
- 选中文本弹出对话框效果(如百度文库)
- Unity 跑马灯效果
- java jnlp_使用Java 7启动JNLP时的NoSuchAlgorithmException
- 复大华韬会基因博物馆项目论证会在北京大学举行
- 数字排在最前,英文字母其次,汉字则按照拼音进行排序,获取中文首字母
- 中国叶酒市场趋势报告、技术动态创新及市场预测
- matlab机器人工具箱 欧拉角,Matlab机器人工具箱(一)
热门文章
- wireshark-win64-3.4.0安装_这9类轴承的安装方法,你可都知道?有哪些需要注意的呢?...
- 为什么你闻不到自己胳肢窝的味道?
- 这相册一出手,哪个长辈搞不定?
- 别说了,叫爸爸吧! | 今日最佳
- 鉴别一个人是否 js 入门的标准竟然是?!
- hadoop 2.7 java_Hadoop2.7环境搭建---Java环境变量
- python中x 1什么意思_Python:A [1:]中x的含义是什么?
- 各高校寒假时间公布_高校放假哪家长?多所高校寒假时间公布!
- python获取系统时间函数_简单记录python的时间函数操作
- 南阳理工计算机全国排名,全国工科实力最强的10所高校排名,