当前位置:网站首页>2022河南萌新联赛第(四)场:郑州轻工业大学 C - 最大公因数
2022河南萌新联赛第(四)场:郑州轻工业大学 C - 最大公因数
2022-08-02 04:31:00 【WA_自动机】
C - 最大公因数
由于 g c d ( a , b ) = = x gcd(a,b)==x gcd(a,b)==x ,则 g c d ( a x , b x ) = 1 gcd(\frac{a}{x},\frac{b}{x})=1 gcd(xa,xb)=1 ,那么这道题就是让我们找 [ l , r ] [l,r] [l,r] 内两个数,其不仅是 x x x 的倍数,在完 x x x 后也互质。
两个相邻的整数是互质的,所以这里找 [ l , r ] [l,r] [l,r] 内两个相邻的 x x x 的倍数就行
例:若存在, g c d ( r / x , r / x − 1 ) gcd(r/x,r/x-1) gcd(r/x,r/x−1) , g c d ( r / x ∗ x , ( r / x − 1 ) ∗ x ) = x gcd(r/x*x,(r/x-1)*x)=x gcd(r/x∗x,(r/x−1)∗x)=x
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;cin>>T;
while(T--)
{
int l,r,x;cin>>l>>r>>x;
int a=(l+x-1)/x*x;
int b=a+x;
if(a<=r && b<=r) cout<<a<<" "<<b<<endl;
else cout<<"-1"<<endl;
}
return 0;
}
边栏推荐
- 2022 Huawei Software Elite Challenge (Preliminary) - Summary
- How to quickly delete the compressed package password?
- 洛谷P2437蜜蜂路线
- 力扣练习——42 二叉树的层次遍历 II
- UE4 创建暂停和结束游戏UI
- 如何运用3DGIS技术整合智慧社区综合管理解决方案
- 【数字IC手撕代码】Verilog固定优先级仲裁器|题目|原理|设计|仿真
- Deep blue college - handwritten VIO operations - the first chapter
- 【七夕】是时候展现专属于程序员的“浪漫”了
- 找倍数(DAY 98)
猜你喜欢
vs2022 编译libmodbus源码
What if some fields don't want to be serialized?
How to decrypt worksheet protection in Excel
Go 语言是如何实现切片扩容的?【slice】
斐波那契数列
2022 Huawei Software Elite Challenge (Preliminary) - Summary
Does Conway's Law Matter for System Architecture?
洛谷P2437蜜蜂路线
Crawler_crawl wasde monthly supply and demand balance table (example)
如何解决QByteArray添加quint16双字节时错误?
随机推荐
Use the advanced timer of GD32F207 to generate hidden bugs in PWM waves
HSCTF2022-re题解
地牢大师(DAY 95)
alibaba数据同步组件canal的实践整理
系统层面知识连接收藏
棋盘问题(DAY 94)
P1012 [NOIP1998 提高组] 拼数
互动投影墙深受展览展示喜爱的原因分析
Visual SLAM Lecture Fourteen - Lecture 13 Practice: Designing a SLAM system (the most detailed code debugging and running steps)
如何解决QByteArray添加quint16双字节时错误?
递归实现组合型枚举(DAY 92)
力扣练习——41 对称二叉树
【数字IC手撕代码】Verilog固定优先级仲裁器|题目|原理|设计|仿真
ROS visualization of 3D target detection
internship:数据库表和建立的实体类及对应的枚举类之间的联系示例
Crawler_crawl wasde monthly supply and demand balance table (example)
找倍数(DAY 98)
康威定律对于系统架构很重要吗?
已更新 联通 电信 tiny模式
Does Conway's Law Matter for System Architecture?