description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def read_array(): x = [] x1 = [] x = input() x = x.split(" ") for v in x: x1.append(int(v)) return x1 x = int(input()) re = [] for r in range(x): x = read_array() a = x[0] b = x[1] if b > a: re.append(b - a) elif a % b == 0: re.append(0) else: re.append(b - a % b) for v in re: print(v)
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
tc = int(input()) for i in range(tc): A = input().split() if int(A[0]) <= int(A[1]): print(int(A[1]) - int(A[0])) elif int(A[0]) % int(A[1]) == 0: print(0) else: print(int(A[1]) * (int(A[0]) // int(A[1]) + 1) - int(A[0]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
results = [] for _ in range(int(input())): a, b = map(int, input().split()) if a % b: results.append(str(b - a % b)) else: results.append("0") print("\n".join(results))
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
n = input() arr = [] arr1 = [] arr2 = [] for i in range(int(n)): arr.append(list(map(int, input().split()))) for j in range(int(n)): arr1.append(int(arr[j][0]) % int(arr[j][1])) arr2.append(int(arr[j][1]) - int(arr1[j])) if arr2[j] == arr[j][1]: arr2[j] = 0 print(arr2[j])
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def get_min(n, s): str_n = str(n) d = len(str_n) count = 0 sum_digits = sum([int(i) for i in str_n]) if sum_digits <= s: return 0 for i in range(d): count += int(str_n[i]) if count > s or count == s and sum_digits > s: return 10 ** (d - i) - int(str_n[i:]) t = int(input()) for i in range(t): n, s = list(map(int, input().split())) print(get_min(n, s))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR RETURN BIN_OP BIN_OP NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def digsum(n): ret = 0 while n > 0: ret += n % 10 n = n // 10 return ret def solve(): n, s = map(int, input().split()) ans = 0 i = 0 while digsum(n) > s and i < 20: d = n % pow(10, i + 1) d = digsum(d) if d != 0: n += (10 - d) * pow(10, i) ans += (10 - d) * pow(10, i) i += 1 print(ans) for _ in range(int(input())): solve()
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for _ in range(int(input())): q, w = input().split() Q = list(map(int, reversed(q))) s = sum(Q) w = int(w) ans = 0 i = 0 while s > w: if Q[i] != 0: add = 10 - Q[i] s -= Q[i] ans += add * 10**i Q[i] += add s += 1 if i + 1 < len(Q): Q[i + 1] += 1 else: Q.append(1) i += 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = int(input()) for i in range(t): a, b = map(int, input().split()) if a < b: print(b - a, flush=True) else: q = a // b r = a % b if r == 0: print(0, flush=True) else: ans = (q + 1) * b - a print(ans, flush=True)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for _ in range(int(input())): n, s = [int(i) for i in input().split()] num = str(n) sum = 0 for i in num: sum += int(i) i = -1 ans = 0 while sum > s: x = int(num[i]) temp = 10 - x temp = temp * 10 ** (abs(i) - 1) ans += temp n += temp num = str(n) t = 0 for j in num: t += int(j) sum = t i -= 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def solver(n, s): if n <= s: return 0 if sum(map(int, list(str(n)))) <= s: return 0 memo = [] X = list(str(n)) for _ in range(1, len(X)): memo.append(int(str(n)[:_]) + 1) memo.append(n) memo = memo[::-1] for i in range(1, len(X) + 1): memo[i - 1] = str(memo[i - 1]) + "0" * (i - 1) memo.append("1" + "0" * len(X)) for i in memo: reached = sum(map(int, list(i))) if reached <= s: return int(i) - n t = int(input()) Testcase = [list(map(int, input().split())) for i in range(t)] for n, s in Testcase: opt = solver(n, s) print(opt)
FUNC_DEF IF VAR VAR RETURN NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = int(input()) def sm(v): return sum([int(i) for i in str(v)]) for it in range(t): n, s = [int(i) for i in input().split()] start = n cur = 1 for i in range(20): d = n % cur if d != 0: n += cur - d if sm(n) <= s: print(n - start) break cur *= 10
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = int(input()) def sum_d(string): return sum(int(x) for x in string) for _ in range(t): n, s = list(map(int, input().split())) start = str(n) if sum_d(start) <= s: print(0) continue for digits in range(1, len(start) + 1): if sum_d(start[-digits:]) == 0: continue new_str = [x for x in start] for x in range(digits): new_str[-1 - x] = "0" if digits == len(start): new_str.insert(0, "1") else: for x in range(len(start) - digits): if new_str[len(start) - digits - 1 - x] == "9": new_str[len(start) - digits - 1 - x] = 0 if x == len(start) - digits - 1: new_str.insert(0, "1") else: new_str[len(start) - digits - 1 - x] = ( int(new_str[len(start) - digits - 1 - x]) + 1 ) break if sum_d(new_str) <= s: new_val = 0 for val in new_str: new_val *= 10 new_val += int(val) print(new_val - n) break
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR STRING IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = input() for i in range(int(t)): s = input() l = s.split(" ") l = list(map(int, l)) if l[0] % l[1] == 0: print(0) else: k = 0 print((int(l[0] / l[1]) + 1) * l[1] - l[0])
ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def solve(): A = list(map(int, input().split())) x = A[0] % A[1] if x == 0: print(0) elif A[0] > A[1]: print(A[1] - x) else: print(A[1] - A[0]) T = int(input()) for i in range(T): solve()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ def gift(): for _ in range(t): a, b = list(map(int, input().split())) c = a % b if c == 0: yield 0 else: yield b - c t = int(input()) ans = gift() print(*ans, sep="\n")
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR NUMBER EXPR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def sum(n): d = 0 for i in list(str(n)): d += int(i) return d for i in range(int(input())): n, s = map(int, input().split()) ans = [] while sum(n) > s: ans.insert(0, str((10 - n % 10) % 10)) n = n // 10 + (1 if n % 10 else 0) if len(ans) == 0: print(0) continue print("".join(ans))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
user = int(input()) userData = [] for i in range(0, user): data = input() data = data.split(" ") userData.append(data) for i in range(0, len(userData)): a = int(userData[i][0]) b = int(userData[i][1]) if a % b == 0: print(0) else: print(b * (1 + int(a / b)) - a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def main(): t = int(input()) while t > 0: t = t - 1 l = str(input()) l = l.split() a = int(l[0]) b = int(l[1]) fun(a, b) def fun(a, b): if a % b == 0: print("0") else: print(b - a % b) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def is_prime(n): if n <= 1: return False for i in range(2, n): if n % i == 0: return False return True def check_div(a, b): if a % b == 0: return 0 if a < b: return b - a else: rest = a // b + 1 return b * rest - a cases = int(input()) for _ in range(cases): a, b = list(map(int, input().split())) print(check_div(a, b))
FUNC_DEF IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN NUMBER IF VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for _ in range(int(input())): n, s = map(int, input().split()) a = [int(i) for i in str(n)] ans = 0 i = 0 if sum(a) <= s: print(0) continue while ans < s and i < len(a): ans += a[i] i += 1 b = [] for j in range(i - 1, len(a)): b.append(a[j]) c = "".join(str(i) for i in b) d = 10 ** len(c) print(d - int(c))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
l = [] for _ in range(int(input())): n, s = map(int, input().split()) new = n d = [] sum = 0 while 1: sum = sum + new % 10 d.append(new % 10) new = new // 10 if new == 0: break d = d[::-1] if sum <= s: l.append(0) continue if d[0] >= s and sum > s: l.append(10 ** len(d) - n) continue sum = 0 for i in range(len(d)): sum = sum + d[i] if sum >= s: index = i break new = n % 10 ** (len(d) - index) l.append(10 ** (len(d) - index) - new) for i in l: print(i)
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
n = int(input()) for i in range(0, n): p = input().rstrip().split(" ") if int(p[0]) % int(p[1]) == 0: print(0) elif int(p[0]) < int(p[1]): print(int(p[1]) - int(p[0])) else: A = int(p[0]) // int(p[1]) + 1 B = A * int(p[1]) print(B - int(p[0]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for _ in range(int(input())): n, s = map(int, input().split()) t = n sm = 0 q = 1 while t: sm += t % 10 t //= 10 ans = 0 while sm > s: ans += q * (10 - n % 10) n += 10 - n % 10 sm = 0 while n % 10 == 0: n //= 10 q *= 10 t = n while t: sm += t % 10 t //= 10 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for t in range(int(input())): a, b = map(int, input().split()) if a % b == 0: ans = 0 else: ans = (a // b + 1) * b - a print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
n = int(input()) numbers = [[int(x) for x in input().split()] for y in range(n)] div = [] for x in range(len(numbers)): if numbers[x][0] % numbers[x][1] == 0: div.append(0) else: div.append(numbers[x][1] - numbers[x][0] % numbers[x][1]) for x in div: print(x)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def digsum(n): summ = 0 while n: summ += n % 10 n //= 10 return summ t = int(input()) for i in range(t): n, s = map(int, input().split()) if digsum(n) <= s: print(0) else: n1 = n n_str = "0" + str(n) n2 = [] for char in n_str: num = int(char) n2.append(num) l = len(n2) for j in range(len(n2)): n2[l - 1] = 0 n2[l - 2] += 1 if sum(n2) <= s: break l -= 1 n2 = n2[::-1] n3 = 0 for i in range(len(n2)): n3 += n2[i] * 10**i print(n3 - n1)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def solve(a, b): if a % b == 0: print(0) else: print(b * (a // b + 1) - a) def main(): t = int(input()) for i in range(t): l = list(map(int, input().split())) solve(l[0], l[1]) main()
FUNC_DEF IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def su(x): s = 0 for d in x: s += int(d) return s for _ in range(int(input())): n, s = input().split() s = int(s) if su(n) <= s: print(0) else: le = len(n) + 1 ans = ["0"] for d in n: ans.append(d) while le > 0: ans[le - 1] = "0" k = le - 1 fl = 1 while fl == 1: if ans[k - 1] == "9": ans[k - 1] = "0" k -= 1 else: ans[k - 1] = str(int(ans[k - 1]) + 1) fl = 0 if su(ans) <= s: st = "".join(ans) print(int(st) - int(n)) break else: le -= 1
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
cases = int(input("")) for i in range(cases): actual_sum = 0 flag = False info = input("").split(" ") digit_sum = int(info[1]) corrector_digits = 0 for j in range(len(info[0])): actual_sum = actual_sum + int(info[0][j]) if actual_sum >= digit_sum and flag == False: if j > 0: corrector_digits = int(info[0][0:j]) + 1 flag = True if actual_sum <= digit_sum: print("0") continue if corrector_digits == 0: print(10 ** int(len(info[0])) - int(info[0])) continue if corrector_digits != 0: while corrector_digits < int(info[0]): corrector_digits = corrector_digits * 10 print(corrector_digits - int(info[0]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER WHILE VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
n = int(input()) a = [] for i in range(n): r = input() a.append(r) for i in range(len(a)): b = a[i] for j in range(len(b)): if b[j] == " ": c = j d = int(b[:c]) e = int(b[c + 1 :]) if d % e == 0: print(0) else: print(e - d % e)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for i in range(int(input())): s = list(map(int, input().split())) if s[0] > s[1]: if s[0] % s[1] == 0: print(0) else: print((int(s[0] / s[1]) + 1) * s[1] - s[0]) else: print(s[1] - s[0])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
rw = int(input()) for wewq in range(rw): n, s = map(int, input().split()) p = list(map(int, list(str(n)))) ps = 0 for i in p: ps += i p.reverse() if ps <= s: print(0) continue for i in range(len(p)): ps -= p[i] p[i] = 0 k9 = 0 j = i while j < len(p) and p[j] == 9: j += 1 k9 += 1 if ps + 1 <= s or ps + 1 <= s - k9 * 9: if i == len(p) - 1: p = p + [1] else: p[i + 1] += 1 break for i in range(len(p)): if p[i] == 10: p[i] = 0 if i == len(p) - 1: p = p + [1] else: p[i + 1] += 1 a = "" p.reverse() for i in p: a += str(i) print(int(a) - n)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR LIST NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR LIST NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def nod(a, b): while a != b: a, b = max(a, b), min(a, b) if a % b == 0: a -= (a // b - 1) * b else: a -= a // b * b return a for i in range(int(input())): a, b = [int(x) for x in input().split()] if a % b == 0: print(0) else: print((a // b + 1) * b - a)
FUNC_DEF WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = int(input()) while t > 0: ab = input().split() a = int(ab[0]) b = int(ab[1]) if a >= b: c = float(a % b) if c == 0: print(int(c)) else: f = float(a / b) d = int(f) e = b * (d + 1) print(e - a) else: print(b - a) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
import sys def divisor(a, b): while a != b: if a > b: a = a - b elif a < b: b = b - a return a num = input() for index in range(0, int(num)): i = 0 str = input().split() a = int(str[0]) b = int(str[1]) if a % b == 0: print(0) elif a % b != 0: if b > a: print(b - a) else: print(b * (a // b + 1) - a)
IMPORT FUNC_DEF WHILE VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for _ in range(int(input())): n, s = map(int, input().split()) sum_of_digit = 0 m = n digit_cnt = 0 while m: sum_of_digit += m % 10 digit_cnt += 1 m //= 10 if sum_of_digit <= s: print(0) continue m = n digit_cnt2 = 0 flag = 0 while m: sum_of_digit -= m % 10 m //= 10 digit_cnt2 += 1 if m and sum_of_digit <= s - 1: m += 1 while digit_cnt2: digit_cnt2 -= 1 m *= 10 print(m - n) flag = 1 break if flag: continue m = 1 while digit_cnt: digit_cnt -= 1 m *= 10 print(m - n)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
import sys t = int(sys.stdin.readline().split()[0]) for line in sys.stdin: a = int(line.split()[0]) b = int(line.split()[1]) steps = 0 if a % b == 0: print("0") else: print(b - a % b)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = int(input()) for i in range(t): a, b = map(int, input().split()) cop_b = b c = 0 i = 2 if a % b == 0: c = 0 elif a > b: remainder = a // b + 1 c = abs(a - remainder * b) elif a < b: c = b - a print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for i in range(int(input())): n, s = map(int, input().split()) l = list(map(int, list(str(n)))) if sum(l) <= s: print(0) continue i = 0 q = l[0] while q < s: i += 1 q += l[i] req = len(l[i:]) x = "".join(map(str, l[i:])) req_num = int(x) mov = 10**req - req_num print(mov)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
n = input() answears = [] for _ in range(int(n)): res = [""] last_index = 0 num = input() for i in num: if i != " ": res[last_index] += i else: res.append("") last_index += 1 if int(res[0]) % int(res[1]) != 0: buf = int(res[0]) / int(res[1]) answears.append(round((int(buf) + 1 - buf) * int(res[1]))) else: answears.append(0) for i in answears: print(i)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR STRING VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def main(): t = int(input()) for _ in range(t): n, s = input().split(" ") s = int(s) total = 0 for nn in n: total += int(nn) ans = 0 p = 1 ten = 1 carry = False while total > s: num = int(n[-p]) if carry: num += 1 if num == 0: carry = False else: ans += ten * (10 - num) total -= num - 1 carry = True ten *= 10 p += 1 print(ans) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for _ in range(int(input())): n, s = map(int, input().split()) a = list(map(int, list(str(n)))) if sum(a) <= s: print(0) else: tot = 0 b = a[::-1] i = 0 while i < len(b) and sum(b) > s: if b[i] == 0: i += 1 continue else: tot += (10 - b[i]) * 10**i b[i] = 0 if i != len(b) - 1: b[i + 1] += 1 i += 1 print(tot)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def check(n, s): sum = 0 while n: sum += n % 10 n //= 10 if sum <= s: return True else: return False t = int(input()) while t: n, s = input().split(" ") n = int(n) s = int(s) t -= 1 p = 0 cnt = 0 while True: if check(n, s): break num = n % 10 if num != 0: cnt += (10 - num) * 10**p n //= 10 if num != 0: n += 1 p += 1 print(cnt)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def suma(num): res = 0 while num > 0: res += num % 10 num = num // 10 return res t = int(input()) for _ in range(t): n, s = map(int, input().split()) _n = n k = 10 if suma(n) > s: while True: n += k // 10 if n % k == 0: k *= 10 if suma(n) <= s: break print(n - _n)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR WHILE NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def main(): n = int(input()) arr = [] for i in range(0, n): a, b = input().split() a, b = int(a), int(b) if a % b == 0: arr.append(0) elif a % b != 0: arr.append(b - a % b) for i in arr: print(i) if __name__ == main(): main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def dig(n): sum = 0 for i in str(n): sum += int(i) return sum t = int(input()) for z in range(t): n, s = map(int, input().split()) p = "" l = list(map(int, str(n).rstrip())) if dig(n) <= s: print(0) else: for i in range(len(l) - 1, -1, -1): if l[i] > 0: p += str(10 - l[i]) l[i - 1] += 1 else: p += "0" if dig(int(p[::-1]) + n) <= s: break print(p[::-1])
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR STRING IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = int(input()) for _ in range(t): a, b = [int(i) for i in input().split()] div = a / b if div == a // b: print(0) else: print((a // b + 1) * b - a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
testCase = int(input()) for i in range(testCase): a, b = map(int, input().split()) i = 1 r1 = a / b r2 = int(a / b) if r1 > r2: r2 = r2 + 1 print(r2 * b - a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = int(input()) for i in range(t): n, s = input().split(" ") tmp = int(n) n = str(n) s = int(s) ar = [0] m = len(n) for j in range(m): ar.append(ar[-1] + ord(n[j]) - ord("0")) if ar[-1] <= s: print(0) continue check = False for j in range(len(ar) - 1, 0, -1): if ar[j] + 1 <= s: ans = 0 cur = 10 for t in range(j + 1, m): cur *= 10 ans = cur * (ord(n[j - 1]) - ord("0") + 1) for t in range(j - 1, 0, -1): cur = cur * 10 ans = ans + (ord(n[t - 1]) - ord("0")) * cur print(ans - tmp) check = True break if check: continue ans = 1 for j in range(m): ans *= 10 print(ans - tmp)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
a = int(input()) i = 1 while i < a + 1: b, c = input().split() j = 0 sum = 0 while j < len(b): sum += int(b[j]) j += 1 num = [] for x in b: num += x ans = 0 k = 1 while sum > int(c) and len(num) - k > 0: if int(num[len(num) - k]) > 0: ans += (10 - int(num[len(num) - k])) * 10 ** (k - 1) sum += 1 - int(num[len(num) - k]) num[len(num) - k] = 0 num[len(num) - k - 1] = int(num[len(num) - k - 1]) + 1 k += 1 if k <= len(num) and sum <= int(c): print(ans) elif int(b) != int(c) and sum != int(c): print(int(10 ** len(num)) - int(b)) else: print("0") i += 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING VAR NUMBER
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
n = int(input()) def divisible(a, b): number = a % b if number == 0: return 0 return b - number for i in range(n): a = list(map(int, input().split())) print(divisible(a[0], a[1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = input("") results = "" for i in range(int(t)): x = input("").split(" ") a = int(x[0]) b = int(x[1]) if a % b == 0: r = 0 else: c = a % b r = b - c results += str(r) + "\n" print(results)
ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for _ in range(int(input())): a, b = map(int, input().split()) if a % b == 0: print("0") else: down = a // b down += 1 print(abs(a - b * down))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
import sys import time sysinput = sys.stdin.readline start_time = time.time() def inp(): return int(sysinput()) def inlt(): return list(map(int, sysinput().split())) def insr(): s = sysinput() return list(s[: len(s) - 1]) def invr(): return map(int, sysinput().split()) t = inp() while t > 0: t -= 1 n, s = inlt() k = n number = [] order = 0 suma = 0 while True: suma += k - 10 * (k // 10) number.append(k - 10 * (k // 10)) order += 1 if k // 10 == 0: break k = k // 10 number.append(0) inc = 0 for i in range(order): if suma > s and number[i] != 0: inc += (10 - number[i]) * 10**i number[i] = 0 j = i + 1 while True: if j >= order: break if number[j] + 1 == 10: number[j] = 0 j += 1 else: number[j] += 1 break elif suma <= s: break suma = sum(number) print(inc)
IMPORT IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER IF VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = int(input()) for _ in range(t): n, s = map(int, input().split()) nsum = 0 ns = str(n) for ni in ns: nsum += int(ni) if nsum <= s: print(0) continue for i in range(19): p = pow(10, i + 1) plus = p - n % p new_n = n + plus ns = str(new_n) nsum = 0 for ni in ns: nsum += int(ni) if nsum <= s: print(plus) break
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for _ in range(int(input())): n, m = map(int, input().split()) ans = 0 q = int(n / m) n1 = m * q if n % m == 0: print(0) if m > n: print(m - n) if n % m != 0 and m < n: n2 = m * (q + 1) print(n2 - n)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
import sys ii = lambda: sys.stdin.readline().strip() idata = lambda: [int(x) for x in ii().split()] def solve(): n, s = idata() n = list(str(n)) summ = 0 ans = 0 for i in range(len(n)): n[i] = int(n[i]) summ = sum(n) if summ <= s: print(0) else: n = n[::-1] n += [0] i = 0 c = 1 while summ > s: if n[i] != 0: summ -= n[i] - 1 ans += (10 - n[i]) * c n[i] = 10 j = 0 while n[i + j] == 10: if j: summ -= 9 j += 1 n[i + j] += 1 i += j - 1 c *= 10 ** (j - 1) i += 1 c *= 10 print(ans) return for t in range(int(ii())): solve()
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = int(input()) for i in range(t): T = 0 n, b = [str(x) for x in input().split()] s = int(b) if len(n) == 1: if int(n) > s: print(10 - int(n)) else: print(0) continue sm = 0 f = 0 k = 0 for j in range(len(n)): sm += int(n[j]) k = j if sm >= s: break for j in range(len(n)): f += int(n[j]) if f <= s: print(0) continue moves = 0 stri = "" if k == 0: moves = 1 for j in range(len(n)): moves *= 10 print(moves - int(n)) else: for j in range(len(n)): if j == k - 1: stri += str(1) elif j >= k: stri += str(0) print(int(stri) - int(n[k:]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for case in range(int(input())): n, s = [int(x) for x in input().split()] cur = [int(x) for x in str(n)] cur.insert(0, 0) ans = int(1e19) temp = [x for x in cur] if sum(temp) <= s: print(0) continue for i in range(len(cur) - 1, 0, -1): if temp[i] == 0: continue temp[i] = 0 j = i - 1 while temp[j] == 9: temp[j] = 0 j -= 1 temp[j] += 1 if sum(temp) <= s: temp2 = [str(x) for x in temp] print(int("".join(temp2)) - n) break
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def solve(n, s): sn = str(n) ans = "" len_sn = len(sn) for i in range(len_sn - 1, -1, -1): ans = str(int(sn[0 : i + 1]) + 1) digit_sum = sum(int(d) for d in ans) if digit_sum <= s: ret = int(ans.ljust(len_sn, "0")) if ret < n: ret *= 10 return ret return int("1" + "0" * len_sn) t = int(input()) for _ in range(t): n, s = map(int, input().split()) digit_sum = sum(int(d) for d in str(n)) if digit_sum <= s: print(0) else: nf = solve(n, s) print(nf - n)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING IF VAR VAR VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP STRING BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
rr = lambda: input().strip() rrm = lambda: map(int, rr().split()) def solve(): n, s = rrm() n = str(n) l = len(n) x = s for i in range(l): x = int(n[i]) if x >= s: break else: s -= x else: return 0 if s < 10 and x == s: x = n[:i] + str(s) + "0" * (l - i - 1) if x == n: return 0 ans = 10 ** (l - i) - int(n[i:]) return ans T = int(rr()) for _ in range(T): ans = solve() print(ans)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def solve(a, b): divided = a / b if divided != int(divided): remainder = b * (int(divided) + 1) - a else: remainder = 0 return remainder count = int(input()) for i in range(count): a, b = list(map(int, input().split())) answer = solve(a, b) print(answer)
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = int(input()) while t > 0: l = [int(i) for i in input().split()] if l[0] % l[1] == 0: print("0") else: q = l[0] // l[1] print((q + 1) * l[1] - l[0]) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
import sys def ans(n, s): n = str(n) if sum(map(int, n)) <= s: return 0 candidates = set() for i in range(1, len(n)): na, nb = n[:i], n[i:] na = str(int(na) + 1) nb = "0" * len(nb) if sum(map(int, na)) + sum(map(int, nb)) <= s: candidates.add(int(na + nb) - int(n)) big = "1" + "0" * len(n) candidates.add(int(big) - int(n)) small = "1" + "0" * (len(n) - 1) if int(small) - int(n) >= 0: candidates.add(int(small) - int(n)) return min(candidates) def ans_slow(n, s): for i in range(0, 10**200): big = n + i big = str(big) if sum(map(int, big)) <= s: return i T = int(input()) for t in range(T): n, s = input().split() n = int(n) s = int(s) print(ans(n, s))
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING BIN_OP STRING BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = int(input()) for _ in range(t): n, s = map(int, input().split()) st = str(n) if sum(map(int, st)) <= s: print(0) else: su = 0 t = 0 options = [] st = "0" + st for i, c in enumerate(st): su += int(c) if su >= s: break else: options.append((t * 10 + int(c) + 1) * 10 ** (len(st) - 1 - i)) t *= 10 t += int(c) print(min(options) - n)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP STRING VAR FOR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def dsum(k): s = 0 while k > 0: s += k % 10 k //= 10 return s t = int(input()) for _ in range(t): n, s = [int(i) for i in input().split()] if dsum(n) <= s: print(0) continue moves = 0 d = 0 while dsum(n) > s: d += 1 e = 10**d if n % e: new_n = n + e - n % e moves += new_n - n n = new_n print(moves)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
import sys readLine = lambda: sys.stdin.readline() readInt = lambda: int(sys.stdin.readline()) readInts = lambda: [int(x) for x in sys.stdin.readline().split(" ")] def main(): t = readInt() for _ in range(t): a, b = readInts() if a % b == 0: print(0) else: print(b - a % b) main()
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
n = int(input()) lst = [] for i in range(n): stp = 0 a, b = input().split() a = int(a) b = int(b) if b > a: stp = b - a lst.append(stp) elif a % b == 0: lst.append(0) else: stp = a % b c = int(a / b) c = c + 1 d = int(c * b) stp2 = min(a - stp, d - a) lst.append(stp2) for i in lst: print(i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
n = int(input()) for _ in range(n): q = input().split(" ") a, b = int(q[0]), int(q[1]) if a % b == 0: print(0) continue x = a // b m = (x + 1) * b - a print(m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for _ in range(0, int(input())): n, s = list(map(int, input().split(" "))) r = str(n) ans = 0 actu = 0 for i in range(0, len(r)): actu += int(r[i]) i = len(r) - 1 while actu > s: actu = 0 n += (10 - int(r[i])) * 10 ** (len(r) - 1 - i) ans += (10 - int(r[i])) * 10 ** (len(r) - 1 - i) r = str(n) for j in range(0, len(r) - 1): actu += int(r[j]) i -= 1 print(ans)
FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
x = int(input()) a = list() for i in range(x): s = list(map(int, input().split())) a.append(s) for i in a: if i[0] % i[1] == 0: print("0") else: l = i[0] // i[1] print((l + 1) * i[1] - i[0])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
import sys for _ in range(int(input())): n, s = map(int, sys.stdin.readline().split()) n_list = list(str(n)) for i in range(len(n_list)): n_list[i] = int(n_list[i]) cnt = 0 if sum(n_list) <= s: cnt = 0 elif n_list[0] >= s: cnt = 10 ** len(n_list) - n else: for i in range(1, len(n_list)): if sum(n_list[0 : i + 1]) >= s: j = "".join(map(str, n_list[0:i])) cnt = (int(j) + 1) * 10 ** len(n_list[i:]) - n break print(cnt)
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = int(input()) for i in range(t): n, s = map(int, input().split()) number = list(str(n)) summation = 0 for digit in number: summation += int(digit) flag = True if summation <= s: flag = False exponent = 0 add = 0 cost = 0 if flag: for digit in number[::-1]: if int(digit) + add == 0: add = 0 else: cost += (10 - (int(digit) + add)) * 10**exponent summation -= int(digit) if not add: summation += 1 add = 1 exponent += 1 if summation <= s: break print(cost)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def calc(n): ans = 0 for i in n: ans += int(i) return ans for nt in range(int(input())): n, s = input().split() s = int(s) f = calc(n) if f <= s: print(0) continue n = n[::-1] if n[0] == "0": ans = [0] flag = 0 diff = f - s else: ans = [10 - int(n[0])] flag = 1 diff = f - s - int(n[0]) for i in range(1, len(n)): x = int(n[i]) if flag: x += 1 diff += 1 if diff <= 0: break if x == 0: flag = 0 diff -= int(n[i]) ans.append(0) continue flag = 1 ans.append(10 - x) diff -= x new = [] flag = 0 for i in ans[::-1]: if i != 0 or i == 0 and flag: flag = 1 new.append(i) else: continue print("".join(map(str, new)))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
count = int(input()) num = [] for y in range(count): n = 2 a = list(map(int, input("").strip().split()))[:n] x = a[0] % a[1] if x == 0: value = 0 else: value = a[1] - x num.append(value) for i in num: print(i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for j in range(int(input())): n, s = tuple(map(int, input().split())) n1 = str(n) l = list(map(int, n1)) if s >= sum(l): print(0) else: t = sum(l) diff = t - s z = 0 for i in reversed(range(len(l))): if t <= s: break elif l[i] != 0: t -= l[i] z += (10 - l[i]) * pow(10, len(l) - 1 - i) if i > 0: l[i - 1] += 1 t += 1 else: t += 1 print(z)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
tests = int(input()) aaa = [] bbb = [] for i in range(0, tests): ab = list(map(int, input().split())) aaa.append(ab[0]) bbb.append(ab[1]) for i in range(0, tests): a = aaa[i] b = bbb[i] if a % b == 0: print(0) else: print(b - a % b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
a = int(input()) h = [] for i in range(0, a): x, y = list(map(int, input().split())) res = 0 if x % y == 0: res = 0 else: d = int(x // y) + 1 res = y * d - x h.append(res) print(*h, sep="\n")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
n = int(input()) for i in range(0, n): x, y = [int(a) for a in input().split()] if x >= y: if x % y != 0: f = x // y d = (f + 1) * y - x else: d = 0 else: d = y - x print(d)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for _ in range(int(input())): a, b = [int(s) for s in input().split()] x = a // b if a % b == 0: print(0) else: print(abs(a - (x + 1) * b))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def func(collection): if len(collection) == 2 and collection[1] >= 0 and collection[0] >= 0: if collection[0] % collection[1] == 0: return 0 else: return abs(collection[0] % collection[1] - collection[1]) temp_ls = [] mv_ls = [] i = 0 temp = True while temp == True: if i == 0: message = int(input("")) elif i <= message: temp_ls = list(map(int, input("").split(" "))) mv_ls.append(func(temp_ls)) else: temp = False i += 1 for i in range(len(mv_ls)): print(f"{mv_ls[i]}", end="\n")
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR NUMBER NUMBER RETURN NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def main(): for _ in range(int(input())): a, b = map(int, input().rstrip().split(" ")) c = 0 k = a // b if a % b == 0: print("0") else: s = b * (k + 1) - a print(s) main()
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
x = int(input()) for z in range(x): n1, s = input().split() n = n1 s = int(s) sm = 0 for k in range(len(n)): sm = sm + int(n[k]) if sm <= s: print(0) else: if int(n[0]) >= s or n[0] == "9": n = "0" + n n = list(n) bruh = 0 i = 0 while bruh < s and i < len(n): bruh += int(n[i]) i += 1 i = i - 2 while n[i] == "9": n[i] = "0" i = i - 1 n[i] = str(int(n[i]) + 1) for a in range(i + 1, len(n)): n[a] = "0" c = "".join(n) print(int(c) - int(n1))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER STRING ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
q = int(input()) def solve(): for i in range(q): arr = [int(i) for i in input().split()] moves = 0 if arr[0] % arr[1] == 0: print(str(0)) else: print(str(arr[1] - arr[0] % arr[1])) solve()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
import sys I = sys.stdin.readline pr = sys.stdout.write def main(): for _ in range(int(I())): a, b = map(int, I().split()) pr(f"{(b * (a // b + 1) - a) * bool(a % b)}\n") main()
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
w = int(input()) a = [] c = 0 for i in range(0, w): p = input().split() a.append(p) for i in range(0, w): r = a[i] t = 0 x = int(r[0]) y = int(r[1]) z = x % y if z == 0: w = 0 elif x > y: w = z - y elif x <= y: w = y - x print(abs(w))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
x = int(input()) listnew = list() for i in range(0, x): list1 = input().split(" ") list2 = [int(i) for i in list1] a = list2[0] b = list2[1] if a % b == 0: listnew.append(0) else: c = a // b d = (c + 1) * b - a listnew.append(d) for i in listnew: print(i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
import sys input = sys.stdin.readline def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): s = input() return list(s[: len(s) - 1]) def invr(): return map(int, input().split()) def digitSum(x): c = 0 while x: c += x % 10 x //= 10 return c def solve(x, y): if digitSum(x) <= y: return 0 xStr = str(x) attempt = 10 ** len(xStr) - x for i in range(len(xStr)): newNumber = int(xStr[: i + 1]) + 1 newNumber *= 10 ** (len(xStr) - i - 1) if digitSum(newNumber) <= y: attempt = newNumber - x return attempt lines = inp() for i in range(lines): v = inlt() print(solve(*v))
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for _ in range(int(input())): n, s = map(int, input().split()) str1 = str(n) s1 = 0 s2 = 0 for j in str1: s2 = s2 + int(j) if s2 <= s: print(0) continue for i in range(len(str1)): s1 += int(str1[i]) if s1 < s: continue else: ans = str1[i:] print(10 ** len(ans) - int(ans)) break
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = int(input()) for tc in range(t): s1, n = input().split(" ") n = int(n) ans = 0 s = list(s1) for i in s: ans += int(i) if ans <= n: print(0) continue else: dig = [] for i in s: dig.append(i) sz = len(dig) ptr = sz - 2 while ptr >= 0: dig[ptr] = str(int(dig[ptr + 1]) + int(dig[ptr])) ptr -= 1 ptr = sz - 2 while ptr >= -1: if ans - int(dig[ptr + 1]) + 1 <= n: break ptr -= 1 while ptr >= 0 and s[ptr] == "9": ptr -= 1 if ptr == -1: ptr = 1 nn = ["1"] nn += s while ptr <= sz: nn[ptr] = "0" ptr += 1 nn1 = "" nn1 = nn1.join(nn) print(int(nn1) - int(s1)) else: nn = s nn[ptr] = str(int(nn[ptr]) + 1) ptr += 1 while ptr < sz: nn[ptr] = "0" ptr += 1 nn1 = "" nn1 = nn1.join(nn) print(int(nn1) - int(s1))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST STRING VAR VAR WHILE VAR VAR ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = int(input()) out = "" while t > 0: t -= 1 a, b = [int(i) for i in input().split(" ")] x = a % b if x == 0: out += f"0\n" else: out += f"{b - x}\n" print(out)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR STRING VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for i in range(int(input())): a, b = list(map(int, input().split())) if a % b != 0: next = a // b + 1 print(next * b - a) else: print(0)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def sod(n): sum = 0 while n: sum += n % 10 n //= 10 return sum t = int(input()) for _ in range(t): n, s = map(int, input().split()) sum = sod(n) if sum <= s: print(0) continue t = list(str(n)) m = len(t) idx = -1 cnt = 0 for i in range(m): cnt += int(t[i]) if cnt < s: idx = i while idx >= 0 and t[idx] == "9": idx -= 1 if idx == -1: t = "0" * (m + 1) t = list(t) t[0] = "1" else: t[idx] = chr(ord(t[idx]) + 1) idx += 1 for i in range(idx, m): t[i] = "0" x = str() for c in t: x = x + c print(int(x) - n)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
def isSum(n, k): sumi = 0 for i in range(0, len(n)): sumi += int(n[i]) if sumi <= k: return True else: return False for _ in range(int(input())): n, k = map(int, input().split()) n = list(str(n)) sumi = 0 for i in range(0, len(n)): sumi += int(n[i]) if sumi <= k: print(0) elif len(n) == 1: if sumi > k: print(10 - int(n[0])) else: j = 1 count = 0 for i in range(len(n) - 1, -1, -1): if i != 0: count += 10**j - int(n[i]) * 10 ** (j - 1) n[i] = str(0) n[i - 1] = str(int(n[i - 1]) + 1) j += 1 if isSum(n, k) == True: break else: count += 10**j - int(n[i]) * 10 ** (j - 1) print(count)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
n = int(input().strip()) t = [] def numb(m): m = m.split() a = int(m[0]) b = int(m[1]) if a <= b: return b - a elif a % b == 0: return 0 else: count = a // b b = b * (count + 1) return b - a for i in range(n): m = input().strip() t.append(numb(m)) for i in range(len(t)): print(t[i])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR RETURN BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
testCases = int(input()) cases = [] for i in range(testCases): cases.append(input()) for i in range(testCases): txt = cases[i].split(" ") a = int(txt[0]) b = int(txt[1]) if a % b == 0: print("0") else: result = a % b skips = b - result print(skips)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
for x in range(int(input())): n = input().split() a = int(n[0]) b = int(n[1]) if a % b == 0: print(0) else: num = int(a / b + 1) print(b * num - a)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = int(input()) for _ in range(t): n, s = input().split() s = int(s) n = int(n) def check(n): res = 0 for i in str(n): i = int(i) res += i return res ans = 0 if check(n) <= s: print(ans) else: ans = 0 pow = 1 for i in range(len(str(n))): dig = n // pow % 10 ad = pow * ((10 - dig) % 10) n += ad ans += ad if check(n) <= s: break pow *= 10 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
import sys input = sys.stdin.readline def f(n): res = 0 for _ in range(20): res += n % 10 n //= 10 return res for _ in range(int(input())): n, s = map(int, input().split()) if f(n) <= s: print(0) continue now = 0 for i in range(len(str(n))): now += (10 - n % 10) * pow(10, i) n //= 10 n += 1 if f(n) <= s: print(now) break
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). -----Output----- For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. -----Example----- Input 5 2 1 1 1 500 4 217871987498122 10 100000000000000001 1 Output 8 0 500 2128012501878 899999999999999999
t = int(input()) for _ in range(t): n, s = map(int, input().split()) n = "{0:019d}".format(n) if sum([int(x) for x in n]) <= s: print(0) continue cnt = 0 for i, x in enumerate(n): if cnt + int(x) + 1 <= s: cnt += int(x) else: break print((int(n[i - 1]) + 1) * 10 ** (19 - i) - int(n[i - 1 :]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER BIN_OP NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER