Minimum Integer
Hazrat Ali
Given three integers li, ri and di, find minimum positive integer xi such that it is divisible by di and it does not belong to the segment [li,ri].
Can you answer all the queries?
Recall that a number x belongs to segment [l,r] if l≤x≤r.
The first line contains one integer q (1≤q≤500) — the number of queries.
Then q lines follow, each containing a query given in the format li ri di (1≤li≤ri≤109). li, ri and di are integers.
For each query print one integer: the answer to this query.
5 2 4 2 5 10 4 3 10 1 1 2 3 4 6 5
6 4 1 3 10
Solution
#include <bits/stdc++.h>
using namespace std;
int main()
{
int q;
cin >> q;
while (q--)
{
long long l, r, d;
cin >> l >> r >> d;
long long ans = 1;
if (l <= d)
{
ans = r / d + 1;
}
cout << ans * d << endl;
}
return 0;
}