Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i+1 (1≤i<n) are adjacent, and so are points n and 1.
There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points.
Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1≤k<n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one.
Input
The first line contains two space-separated integers n and m (2≤n≤100000, 1≤m≤200000) — the number of points and the number of segments, respectively.
The i-th of the following m lines contains two space-separated integers ai and bi (1≤ai,bi≤n, ai≠bi) that describe a segment connecting points ai and bi.
It is guaranteed that no segments coincide.
Output
Output one line — “Yes” if the image is rotationally symmetrical, and “No” otherwise (both excluding quotation marks).
You can output each letter in any case (upper or lower).
Examples
Input
12 6
1 3
3 7
5 7
7 11
9 11
11 3
Output
Yes
Input
9 6
4 5
5 6
7 8
8 9
1 2
2 3
Output
Yes
Input
10 3
1 2
3 2
7 2
Output
No
Input
10 2
1 6
2 7
Output
Yes
Note
The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center.
题意
给你一个n个点的圈,其上有m条线段,求该图形是否为旋转对称图形。
题解
感谢实验室的大佬。
我们可以发现,当你对这个图形旋转N度之后他可以重叠自身,那么当你旋转n的整数倍的时候他必然也可以重叠自身。现在我们已知旋转360度,也就是n个点的时候图形必然可以与自身重叠,所以如果这个图形是一个旋转对称图形,那么他的旋转重合度数必然是n的因子,并且可以排除大于n/2的情况,因为当旋转角度大于n/2时,必有一个小于n/2的满足。
所以我们只需要暴力枚举这些因子角度,然后判断是不是符合条件即可
(我后来发现判断也有一点坑点,不过写了才知道,具体看代码)
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<math.h>
#include<vector>
#include<stack>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<stdio.h>
#include<functional>
#include<time.h>
#pragma warning(disable:6031)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e5 + 10;
const ll mode = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979323846264338327950;
template <class T> inline T min(T a, T b, T c) { return min(min(a, b), c); }
template <class T> inline T max(T a, T b, T c) { return max(max(a, b), c); }
template <class T> inline T min(T a, T b, T c, T d) { return min(min(a, b), min(c, d)); }
template <class T> inline T max(T a, T b, T c, T d) { return max(max(a, b), max(c, d)); }
vector<int>ang;
vector<int>mapp[maxn];
int main()
{
int n, m;
int flag = 1;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n / 2; i++)
{
if (n%i == 0)
ang.push_back(i);
}
for (int i = 0; i < m; i++)
{
int s, t;
scanf("%d %d", &s, &t);
if (s > t) swap(s, t);
mapp[s].push_back(t - s);
mapp[t].push_back((s - t + n - 1) % n + 1);
}
for (int i = 1; i <= n; i++)
sort(mapp[i].begin(), mapp[i].end());
for (int i = 0; i < ang.size(); i++)
{
flag = 1;
int now = ang[i];
for (int j = 1; j <= n; j++)
{
if (mapp[j].size() != mapp[(j + now - 1) % n + 1].size())
{
flag = 0;
break;
}
for (int k = 0; k < mapp[j].size(); k++)
{
if (mapp[(j + now - 1) % n + 1][k] != mapp[j][k])
{
flag = 0;
break;
}
}
if (flag == 0) break;
}
if (flag == 1) break;
}
if (flag == 0) printf("No\n");
else printf("Yes\n");
return 0;
}