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. Activiti工作流的定义部署和执行

        工作流引擎 个人觉得直接理解工作流引擎概念有点难度,我们可以先通过了解工作流引擎的职责再反过来理解工作流引擎,工作流引擎一般都做两件事情: 1.定义流程,也就是给我们提供某种规范来定义规则,以 ...

  2. Django之Template

    模板层(template) 概念:  模板与html的区别:  模板=html+模板语法 模板语法: 1 变量:       {{}}    深度查询: 通过句点符.    列表,字典    clas ...

  3. 如何在sublime编辑器中,执行命令行脚本

    我有个愿意,在执行命令行时,不打开那个黑乎乎命令行窗口,如果编辑器内置支持就好了. 打开vs code 和 sublime,分别按快捷键 Ctrl + ·(tab键上面那个键),vs code可以提供 ...

  4. 详解PHP操作Memcache缓存技术提高响应速度的方法

    本文转载http://blog.csdn.net/zhihua_w  不错的博客,仅供本人学习之用 一般来说,如果并发量不大的情况,使不使用缓存技术并没有什么影响,但如果高并发的情况,使用缓存技术就显 ...

  5. <数据结构与算法分析>读书笔记--运行时间计算

    有几种方法估计一个程序的运行时间.前面的表是凭经验得到的(可以参考:<数据结构与算法分析>读书笔记--要分析的问题) 如果认为两个程序花费大致相同的时间,要确定哪个程序更快的最好方法很可能 ...

  6. linux如何查看端口被哪个进程占用

    1.lsof -i:端口号 2.netstat -tunlp|grep 端口号 都可以查看指定端口被哪个进程占用的情况 工具/原料   linux,windows xshell 方法/步骤     [ ...

  7. http/2 多路复用技术

    虽然 HTTP 1.1 默认启用长TCP连接,但所有的请求-响应都是按序进行的(这里的长连接可理解成半双工协议.即便是HTTP 1.1引入了管道机制,也是如此).复用同一个TCP连接期间,即便是通过管 ...

  8. C++ 实现strcpy

    strcpy库函数的原型: // 把src字符串拷贝到dest,并返回dest char *strcpy(char *dest, const char *src) 注意点: 1.形参src用const ...

  9. sql server使用的相关基础知识

    1.表的管理--表和列的命名 必须以字母开头 长度不能超过128字符 不要使用sql server的保留字 只能使用如下字符A-Z,a-z,0-9,$,#,_等等 2.表的管理--支持的数据类型 字符 ...

  10. C#中,使用显式类型转换(int)和Math.Round方法,将浮点数转换为整数的区别

    主要区别就是,显式类型转换(int)是将浮点数的整数部分截取出来,然后转换为整数,所以相当于是向下取整.而Math.Round方法是对浮点数进行四舍五入后,转换为整数. 新建一个.NET Core控制 ...