about summary refs log tree commit diff
path: root/codechef/mgame.c
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-01-14 20:41:09 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-01-14 20:41:09 +0700
commitce56bd193a7c8c6437443227cd3abb51134e3e7a (patch)
tree590c003d9f99e9912e0618a8c77d73ed2b481d20 /codechef/mgame.c
parentbf538954817e568322c83030dd2fbc688a3ee13d (diff)
downloadcp-ce56bd193a7c8c6437443227cd3abb51134e3e7a.tar.gz
At least I managed to stay in top 10%
Diffstat (limited to 'codechef/mgame.c')
-rw-r--r--codechef/mgame.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/codechef/mgame.c b/codechef/mgame.c
new file mode 100644
index 0000000..41ef005
--- /dev/null
+++ b/codechef/mgame.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+#define sqr(x) ((x) * (x))
+
+int main() {
+	long long t, n, p, diff, u, v;
+	scanf("%lld", &t);
+	while(t--) {
+		scanf("%lld %lld", &n, &p);
+		if (n < 3) {
+			printf("%lld\n", p * p * p);
+			continue;
+		}
+
+		diff = p - n;
+		if (diff % 2) {
+			u = n / 2, v = diff/2;
+			printf("%lld\n", (u+v*3+2)*(u+v*3+3) + v*(v+1)*3 + 1);
+		} else {
+			printf("%lld\n", sqr(p/2 + diff + 1) + sqr(diff)*3/4);
+		}
+	}
+	return 0;
+}