Educational Codeforces Round 58 (Rated for Div. 2) A. Minimum Integer

题解

题目大意 让你找到最小的能被d整除且不在[l, r]范围内的数字

考虑小于l的情况 最小为d 大于r的情况 (r/d+1)*d第一个大于r的d的倍数

AC代码

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;

int main()
{
#ifdef LOCAL
	//freopen("C:/input.txt", "r", stdin);
#endif
	int T;
	cin >> T;
	while (T--)
	{
		ll l, r, d;
		cin >> l >> r >> d;
		if (d < l)
			cout << d << endl;
		else
			cout << (r / d + 1) * d << endl;
	}

	return 0;
}

猜你喜欢

转载自blog.csdn.net/CaprYang/article/details/86419071