#include #include using namespace std; class Func { public: Func(size_t n) : N(n), F(n, -1) { } Func(Func& other) : N(other.N), F(other.F.begin(), other.F.end()) { } void Set(size_t x, int v) { if (F[x]<0) { F[x] = v; for (size_t y=0; y=0) { Set((x*y) % N, (v*w) % N); } } } else if (F[x]!=v) { throw "conflict"; } } const size_t N; vector F; ~Func() { } private: }; long long nb = 0; void Fill(Func &f, size_t x) { if (x==f.N) { nb++; } else if (f.F[x]>=0) { Fill(f, x+1); } else { for (int v=0; v