CodeforcesJul 18, 2025

Minimum Integer

Hazrat Ali

Codeforces

Given three integers liri 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 lxr.

Input

The first line contains one integer q (1q500) — the number of queries.

Then q lines follow, each containing a query given in the format li ri di (1liri109). liri and di are integers.

Output

For each query print one integer: the answer to this query.

Example
Input
5
2 4 2
5 10 4
3 10 1
1 2 3
4 6 5
Output
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;
}

 

Comments