codeforce 1101A Minimum Integer(思维水题)
很常见的div2的开场题…开始一看1e9觉得还行, 后来才知道这题无法枚举, 先来复习一下复杂度的知识: 1e6基本安全, 1e7大可一试, 1e8很危险, 1e9必超时(int最多存1e9)
枚举不成只能找规律了, 仔细想一想可以发现, 当d<l时, 答案一定是d, 可当d>l时, 应该是(r/d+1)*d, 也就是d在[l,d]区间里的因子+1(如果区间里没有就是1)
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
using namespace std;
#define ms(x, n) memset(x,n,sizeof(x));
typedef long long LL;
const LL maxn = 1e9+10;
int main()
{
LL q, l, r, d;
cin >> q;
while(q--){
cin >> l >> r >> d;
if(d < l)
cout << d << endl;
else
cout << (r/d+1)*d << endl;
}
return 0;
}