zoukankan      html  css  js  c++  java
  • CF w1d3 A. Minimum Integer

    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;
    }
    
  • 相关阅读:
    CSPS模拟 65
    CSPS模拟 64
    $color$有色图
    CSPS模拟 63
    CSPS模拟 62
    CSPS模拟 61
    CSPS模拟 60
    CSPS模拟 59
    go中单链表
    MYSQL-联合索引
  • 原文地址:https://www.cnblogs.com/LiangYC1021/p/12688909.html
Copyright © 2011-2022 走看看