CF w1d3 A. Minimum Integer

时间:2020-04-13 09:23:38   收藏:0   阅读:46

You are given q queries in the following form:

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.

Input

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, 1≤di≤109). li, ri 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

#include<bits/stdc++.h>
using namespace std;
void solve()
{
	long long l,r,d,x=0,tmp;
	cin>>l>>r>>d;
	if(l>d)x=d;
	else x=((r/d)+1)*d;
	cout<<x<<endl;
}
int main()
{
	int q;
	cin>>q;
	while(q--)solve();
	return 0;
}

原文:https://www.cnblogs.com/LiangYC1021/p/12688909.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!