QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#607316 | #8932. Bingo | UESTC_NLNS# | RE | 0ms | 0kb | Java8 | 2.2kb | 2024-10-03 14:40:31 | 2024-10-03 14:40:31 |
answer
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
static String o = "000000000000000000000000000000000";
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt(); // Number of test cases
sc.nextLine(); // Consume newline
for (int i = 0; i < t; i++) {
String[] input = sc.nextLine().split(" ");
String n1 = input[0];
String m1 = input[1];
BigInteger n = new BigInteger(n1);
BigInteger m = new BigInteger(m1);
// Case 1: if n < m, simply output m
if (n.compareTo(m) < 0) {
System.out.println(m);
continue;
}
// a1 is the smallest multiple of m larger than n
BigInteger a1 = (n.divide(m).add(BigInteger.ONE)).multiply(m);
String a1Str = a1.toString();
// Increment n by 1 and check if m is present in n1
n = n.add(BigInteger.ONE);
n1 = n.toString();
if (n1.contains(m1)) {
System.out.println(n1);
continue;
}
int lm = m1.length();
// Prepare for the next part of the calculation
String n21 = n1.substring(0, n1.length() - 2 * lm - 3);
String n2 = n1.substring(n1.length() - 2 * lm - 3);
String a2 = "-";
for (int j = 0; j <= n2.length() - lm; j++) {
String a3 = n2.substring(0, j) + m1 + o.substring(0, n2.length() - lm - j);
if (a2.equals("-") || a3.compareTo(n2) >= 0) {
a2 = (new BigInteger(a2).compareTo(new BigInteger(a3)) < 0) ? a2 : a3;
}
}
a2 = n21 + a2;
// Compare the lengths and print the result
if (a1Str.length() < a2.length()) {
System.out.println(a1Str);
} else if (a2.length() < a1Str.length()) {
System.out.println(a2);
} else {
System.out.println(a1Str.compareTo(a2) < 0 ? a1Str : a2);
}
}
sc.close();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
6 7 3 12 3 9 10 249 51 1369 37 2 1