跳到正文

题解

P8443 gcd

Svemit约 1 分钟
原文
文章信息与版本

文章信息

发布
2022年7月27日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 1 分钟
题目
P8443

版本

  1. v1当前

题目传送门https://www.luogu.com.cn/problem/P8443

这题其实就两种情况

如果l/x==r/x那答案显而易见是l/x

这时我们只需要输出l/x就行了

如果l/x!=r/x的话

因为分子是递增的

所以我们要求的也只是gcd(l/x,l/x+1,l/x+2…)这样相邻的数

众所周知相邻数的

最大公约数

是1 代码:

C++
#include<bits/stdc++.h>
using namespace std;
long long t,l,r,x;
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>l>>r>>x;
		if(l/x==r/x)
		  cout<<l/x<<endl;
		else
		  cout<<"1"<<endl;
	}
	return 0;
}
原文