Created
March 26, 2020 18:04
-
-
Save belushkin/627e7e1fa05e1839ded3c17b7f40f613 to your computer and use it in GitHub Desktop.
Divisibility Problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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