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. Android Studio打开SDK更新对话框

    再进行android自动化时,有时需要用到android的一些api,但苦于找不到 api文档,各种论坛查看是否有自己所需要的api,甚是麻烦.下面介绍如何通过 android studio将 and ...

  2. arcgis api for javascript中使用proxy.jsp

    当我们使用arcgis api for javascript 查询arcgis服务时,如果查询的参数很长时,通过get方式提交会查询不到结果,因为get方式提交的参数有长度限制,需要通过代理的方式使用 ...

  3. C#反射の反射详解

    C#反射の反射详解(点击跳转)C#反射の反射接口(点击跳转)C#反射反射泛型接口(点击跳转)C#反射の一个泛型反射实现的网络请求框架(点击跳转) 一.什么是反射 反射(Reflection):这是.N ...

  4. Iris框架源码阅读和分析

    iris包结构简介 iris包含了很多包,下面这些是分析过程中接触到的东西. 能力有限,多多包涵,欢迎联系QQ:2922530320 一起交流 context包包含: Context (接口) con ...

  5. JS进阶之---this的指向

    this到底指向什么地方,决定于函数的调用方式. 1. 指向全局变量 --- 函数被单独调用的时候 function fn() { console.log( this.a ); } var a = 2 ...

  6. OnlineJudgeServer运行

    我在这如下这两篇文章都说过青岛OJ相关的 OnlineJudgeFE之前端二次开发 青岛大学开源OJ平台搭建 今天我还是要来讲讲关于这个青岛OJ. 青岛OJ采用的是完全的前后端分离架构. Online ...

  7. JAVA 第九周学习总结

    20175308 2018-2019-2 <Java程序设计>第九周学习总结 教材学习内容总结 准备工作 下载MYSQL数据库管理系统 前往MYSQL官网的下载页面,选择相应平台的MYSQ ...

  8. AI 线性代数

    1.标量.向量.矩阵和张量 1)标量(scalar),一个数,例如自然数和实数. 2)向量(vector),一列有序数.可以看作只有一列的矩阵. 3)矩阵(matrix),二维数组.转置(transp ...

  9. Python文学家为Python写的一首词?(附中英文版)

    The Zen of Python, by Tim Peters (Python之禅 by Tim Peters) Beautiful is better than ugly. (优美胜于丑陋(Pyt ...

  10. Hive 表分区

    Hive表的分区就是一个目录,分区字段不和表的字段重复 创建分区表: create table tb_partition(id string, name string) PARTITIONED BY ...