0分求助
查看原帖
0分求助
815075
hzy99999楼主2023/4/15 10:01
#include<iostream>
using namespace std;
typedef long long LL;
int get(int a, int b)//求最小公倍数
{
	while (b)
	{
		int t = a % b;
		a = b;
		b = t;
	}
	return a;
}
int main()
{
	int T;
	scanf("%d", &T);
	while (T--)
	{
		int a, b;
		LL n;
		scanf("%lld%d%d", &n, &a, &b);//a<b
		int t = get(b, a);//最大公因数
		LL t0 = (LL)a * b / (LL)t;//最小公倍数
		LL res = ((n - 1) / t0) * a + 1;//即原先总长整除最小公倍数+起点0 
		printf("%lld\n", res);
	}
	return 0;
}
2023/4/15 10:01
加载中...