-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProblemB.java
98 lines (83 loc) · 2.41 KB
/
ProblemB.java
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
QReader in = new QReader();
QWriter out = new QWriter();
BigInteger four = new BigInteger("4");
BigInteger two = new BigInteger("2");
BigInteger six = new BigInteger("6");
int t = in.nextInt();
for(int i = 0; i < t; i++) {
BigInteger n = new BigInteger(in.next());
BigInteger a = n.multiply(n.add(BigInteger.ONE)).divide(two);
BigInteger b = n.multiply(n.add(BigInteger.ONE)).multiply(n.multiply(two).add(BigInteger.ONE)).divide(six);
BigInteger sum = a.add(b);
sum = sum.divide(two);
out.println(sum);
}
out.close();
}
}
class QReader {
private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
private StringTokenizer tokenizer = new StringTokenizer("");
private String innerNextLine() {
try {
return reader.readLine();
} catch (IOException e) {
return null;
}
}
public boolean hasNext() {
while (!tokenizer.hasMoreTokens()) {
String nextLine = innerNextLine();
if (nextLine == null) {
return false;
}
tokenizer = new StringTokenizer(nextLine);
}
return true;
}
public String nextLine() {
tokenizer = new StringTokenizer("");
return innerNextLine();
}
public String next() {
hasNext();
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
class QWriter implements Closeable {
private BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
public void print(Object object) {
try {
writer.write(object.toString());
} catch (IOException e) {
return;
}
}
public void println(Object object) {
try {
writer.write(object.toString());
writer.write("\n");
} catch (IOException e) {
return;
}
}
@Override
public void close() {
try {
writer.close();
} catch (IOException e) {
return;
}
}
}