#include #include #include int gcd(int a, int b) { while (a != 0) { int c = a; a = b%a; b = c; } return (b<0) ? -b : +b; } #define MAX 20000 bool seen[MAX]; int unseen = 1; int other(int p) { seen[p] = true; while (seen[unseen]) { unseen++; } for (int v=unseen; v