-
Notifications
You must be signed in to change notification settings - Fork 0
/
clique.c
41 lines (34 loc) · 826 Bytes
/
clique.c
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
#include <stdio.h>
int pow2(int a) {
return a * a;
}
int divceil(int x, int y) {
return 1 + ((x - 1) / y);
}
int turan(int n, int k) {
return (pow2(n) - (n % k) * pow2(divceil(n, k)) - (k - (n % k)) * pow2(n / k) ) / 2;
}
int bin(int n, int e, int first, int last) {
int middle = (first + last) / 2;
if (middle == n) {
return n;
}
if (e > turan(n, middle)) {
if (e <= turan(n, middle + 1)) {
return middle + 1;
} else {
return bin(n, e, middle + 1, last);
}
} else {
return bin(n, e, first, middle - 1);
}
}
int main() {
int q, nodes, edges;
scanf("%d", &q);
for (int a0 = 0; a0 < q; a0++) {
scanf("%d %d", &nodes, &edges);
printf("%d\n", bin(nodes, edges, 1, nodes));
}
return 0;
}