Skip to content

Instantly share code, notes, and snippets.

@belushkin
Created March 26, 2020 18:04
Show Gist options
  • Save belushkin/627e7e1fa05e1839ded3c17b7f40f613 to your computer and use it in GitHub Desktop.
Save belushkin/627e7e1fa05e1839ded3c17b7f40f613 to your computer and use it in GitHub Desktop.
Divisibility Problem
import java.util.*;
public class cf {
public static void main(String[] args) {
// Use the Scanner class
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
for (int i = 0; i < n; i++) {
String s = sc.nextLine();
String[] result = s.split(" ");
int a = Integer.parseInt(result[0]);
int b = Integer.parseInt(result[1]);
if (b > a) {
System.out.println(b-a);
} else if (a % b == 0){
System.out.println(0);
} else {
System.out.println(((a/b)*b + b)-a);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment