Educational Codeforces Round 58 (Rated for Div. 2)(A. Minimum Integer)
A. Minimum Integer
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output
You are given qq queries in the following form:
Given three integers lili, riri and didi, find minimum positive integer xixi such that it is divisible by didi 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 qq lines follow, each containing a query given in the format lili riri didi (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<iostream> using namespace std; int main() { long long int n,x,y,z,t1,t2,t3; cin>>n; while(n--) { cin>>x>>y>>z; t1=x/z; t3=x%z; t2=y/z; if(t1<1) { cout<<(t2+1)*z<<endl; } else { if(t1==1&&t3==0) cout<<(t2+1)*z<<endl; else cout<<z<<endl; } } return 0; }
測試樣例:
Test: #1
Input
5
2 4 2
5 10 4
3 10 1
1 2 3
4 6 5
Output
6
4
1
3
10
Test: #2
Input
5
1 1000000000 1
1 1000000000 1000000000
2 1000000000 1
1 999999999 1000000000
5 6 5
Output
1000000001
2000000000
1
1000000000
10