当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

ADSP21489工程中LDF文件配置详解

The practice of alibaba, data synchronization component canal

ADSP21489仿真:Failed to set breakpoint: Can‘t set breakpoints in the current state: Running

batch_size of deep learning foundation

UE4 创建开始游戏界面UI

How to decrypt worksheet protection in Excel

压缩包密码如何快速删除?

Visual SLAM Lecture Fourteen - Lecture 13 Practice: Designing a SLAM system (the most detailed code debugging and running steps)

如果有些字段不想进行序列化怎么办?

PDF文件转换格式
随机推荐
P1012 [NOIP1998 提高组] 拼数
Minecraft 1.18.1、1.18.2模组开发 23.3D动画盔甲制作
How to decrypt worksheet protection in Excel
使用pycharm debug 深度学习代码
W25Q16 存储器(Flash)
学内核之五:问题一,关于上下文切换
翻转(DAY 97)
acwing 最大数
【数字IC手撕代码】Verilog固定优先级仲裁器|题目|原理|设计|仿真
UE4 创建暂停和结束游戏UI
The line chart with square PyQt5_pyqtgraph mouse
ADSP21489仿真:Failed to set breakpoint: Can‘t set breakpoints in the current state: Running
Minecraft 1.18.1, 1.18.2 module development 23.3D animation armor production
Use the advanced timer of GD32F207 to generate hidden bugs in PWM waves
PDF文件转换格式
internship:数据库表和建立的实体类及对应的枚举类之间的联系示例
YOLOV5学习笔记(四)——项目目录及代码讲解
UE4 蓝图实现AI随机移动
11种你需要了解的物联网(IoT)协议
力扣练习——38 分割回文串