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][li,ri].

Can you answer all the queries?

Recall that a number xx belongs to segment [l,r][l,r] if l≤x≤rl≤x≤r.

Input

The first line contains one integer qq (1≤q≤5001≤q≤500) — the number of queries.

Then qq lines follow, each containing a query given in the format lili riri didi (1≤li≤ri≤1091≤li≤ri≤109, 1≤di≤1091≤di≤109). lili, riri and didi 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 题目链接:CodeForces - 1101A水题一个,但是数据量略大不足以让我们暴力随便过。
那么便思考一下找公式就行了,
观察可知,当d小于L的时候,答案就是d
否则,答案是(r/d+1)*d; 我的AC代码:
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int q;
int l,r;
int d;
int main()
{
gbtb;
cin>>q;
while(q--)
{
cin>>l>>r>>d;
int flag=;
if(d<l)
{
cout<<d<<endl;
continue;
}else
{
int ans=(r/d+)*d;
cout<<ans<<endl;
}
}
return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}
 

Minimum Integer CodeForces - 1101A (思维+公式)的更多相关文章

  1. Codeforces 424A (思维题)

    Squats Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Statu ...

  2. CodeForces - 417A(思维题)

    Elimination Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit  ...

  3. Doors Breaking and Repairing CodeForces - 1102C (思维)

    You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consi ...

  4. CodeForces 816C 思维

    On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as fo ...

  5. CF1101A Minimum Integer 模拟

    题意翻译 题意简述 给出qqq组询问,每组询问给出l,r,dl,r,dl,r,d,求一个最小的正整数xxx满足d∣x d | x\ d∣x 且x̸∈[l,r] x \not\in [l,r]x̸∈[l ...

  6. codeforces 1244C (思维 or 扩展欧几里得)

    (点击此处查看原题) 题意分析 已知 n , p , w, d ,求x , y, z的值 ,他们的关系为: x + y + z = n x * w + y * d = p 思维法 当 y < w ...

  7. CodeForces - 417B (思维题)

    Crash Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status ...

  8. The Contest CodeForces - 813A (思维)

    Pasha is participating in a contest on one well-known website. This time he wants to win the contest ...

  9. 3-palindrome CodeForces - 805B (思维)

    In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so ...

随机推荐

  1. Python3编写网络爬虫09-数据存储方式二-JSON文件存储

    2.JSON文件存储 全称为JavaScript Object Notation 通过对象和数组的组合来表示数据,构造简洁且结构化程度非常高.是一种轻量级的数据交换格式 2.1 对象和数组 在Java ...

  2. 跨域访问的解决方案(非HTML5的方法:JSONP)

    http://supercharles888.blog.51cto.com/609344/856886 跨域访问一直是困扰很多开发者的问题之一.因为涉及到安全性问题,所以跨域访问默认是不可以进行的,否 ...

  3. DAG 模型 stacking boxes 动态规划

    题目:UVA 103 stacking boxes 题目大意: 给你两个数,一个是盒子的个数,一个是每一个盒子的维数.将一个个盒子互相装起来,让你求最多可以装多少个,要求字典序最小. 解析:这个就是盒 ...

  4. easyUI tab页的显示与隐藏

    每天学习一点点 编程PDF电子书免费下载: http://www.shitanlife.com/code 隐藏:tab_option = $('#tabid').tabs('getTab'," ...

  5. ucml 子业务组件与行为参与者业务组件

  6. Myeclipse 启动报错 Failed to create the java Virtual Machine

    1.找到Myeclipse的安装目录 2.找到myeclipse.ini文件 3.打开myeclipse文件 你把原来的jvm.dll文件路径配置改成你的jdk安装路径中的jvm.dll路径 即: C ...

  7. Shell获取指定时间

    时区基本知识 相差一个时区(经度15度)时间相差一小时.简单计算口诀:1.同一个时区的相差时间用减法,2.不同时区的相差时间用加法.3东加西减.例如一,东八区是8点,问东1区几点.根据上面口诀1,算: ...

  8. 分布式RPC框架性能大比拼 dubbo、motan、rpcx、gRPC、thrift的性能比较

    Dubbo 是阿里巴巴公司开源的一个Java高性能优秀的服务框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和 Spring框架无缝集成.不过,略有遗憾的是,据说在淘宝内部,dub ...

  9. jsp中使用原生js实现异步交互

    Ajax的工作原理相当于在用户和服务器之间加了—个中间层,使用户操作与服务器响应异步化.并不是所有的用户请求都提交给服务器,像—些数据验证和数据处理等都交给Ajax引擎自己来做,只有确定需要从服务器读 ...

  10. es3的语法来模拟es5的bind方法

    // 简单版 Function.prototype.bind = function(context) { var self = this; return function() { self.apply ...