Close
Close

Help me in reducing Execution Time of the code

   Qwerty-1234

A. Minimum Integer

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 lxr

.

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≤liri≤109, 1≤di≤109). li, ri and di

are integers.

Output

For each query print one integer: the answer to this query.

<strong>CODE:</strong>

n=int(input())
prob=list()
for i in range(n):
    x=list(map(int,input().split()))
    prob.append(x)
for i in range(n):
    l,r,d=prob[i][0],prob[i][1],prob[i][2]
    for j in range(1,1000000000):
        if j>=l and j<=r:
            continue
        elif (j%d)==0 and j!=0:
            print(j)
            break

 

The above code should run <=1 sec.


Answers

Ask Yours
Post Yours
Write your answer