-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloWorld.java
More file actions
51 lines (40 loc) · 1.46 KB
/
Copy pathHelloWorld.java
File metadata and controls
51 lines (40 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.io.*;
import java.math.BigInteger;
import java.util.Scanner;
class HelloWorld {
public static void main(String args[] ) throws Exception {
BigInteger n;
BigInteger sum,k,rem;
BigInteger test_cases;
Scanner reader = new Scanner(new FileReader("input.txt"));
test_cases = reader.nextBigInteger();
while (test_cases.compareTo(BigInteger.ZERO) == 1 && reader.hasNext()) {
n = reader.nextBigInteger();
k = reader.nextBigInteger();
sum = n.multiply(n.add(BigInteger.ONE));
sum = sum.divide(new BigInteger("2"));
if (sum.remainder(k)== BigInteger.ZERO) {
System.out.println(0);
test_cases.subtract(BigInteger.ONE);
continue;
}
if (sum.compareTo(k) == 1)
{
System.out.println(sum.subtract(k));
test_cases.subtract(BigInteger.ONE);
continue;
}
if (sum.compareTo(k) == -1)
{
rem = k.remainder(sum);
rem = sum.subtract(rem);
System.out.println(rem);
test_cases.subtract(BigInteger.ONE);
continue;
}
if (k.equals(BigInteger.ZERO))
{
}
}
}
}