You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.2 KiB
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
template <>
struct hash<pair<int, int>>
{
size_t operator()(const pair<int, int> &v) const
{
return *((long long *)&v);
}
};
int main()
{
unordered_set<pair<int, int>> S;
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++)
{
int x, y;
scanf("%d%d", &x, &y);
x--, y--;
if (x > y) swap(x, y);
S.insert({x, y});
}
vector<int> v;
for (long long i = 1; i * i <= n; i++)
if (n % i == 0)
{
v.push_back(i);
if (i != 1) v.push_back(n / i);
}
for (auto i : v)
if (n % i == 0)
if (all_of(S.begin(), S.end(), [&](const pair<int, int> &p) {
int x = (p.first + i) % n;
int y = (p.second + i) % n;
if (x > y) swap(x, y);
return S.count({x, y});
}))
{
puts("Yes");
return 0;
}
puts("No");
return 0;
}