#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=1e5+5;
ll n, k, a[nx], b[nx], c[nx], d[nx], st, l, ans=1e18, cnta, cntb;
vector<ll> r[nx];
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>k;
for (int i=1; i<=k; i++) cin>>a[i]>>b[i]>>c[i]>>d[i], r[a[i]].push_back(b[i]);
for (int t=1; t<n; t++)
{
if ((n%t)!=0) continue;
cnta=cntb=0;
for (int i=1; i<=n; i++)
{
l=(((i-1)/t)%2);
//cout<<"debug "<<t<<' '<<i<<' '<<l<<'\n';
if ((n/t)%2==0) cnta+=n/2;
else cnta+=(n/t)/2*t+l*t;
for (auto x:r[i])
{
if ((((x-1)/t)%2)^l) cnta--;
else cnta++;
}
//cout<<"lvl "<<i<<' '<<cnta<<'\n';
l^=1;
if ((n/t)%2==0) cntb+=n/2;
else cntb+=(n/t)/2*t+l*t;
for (auto x:r[i])
{
if ((((x-1)/t)%2)^l) cntb--;
else cntb++;
}
}
//cout<<"t "<<t<<' '<<cnta<<' '<<cntb<<'\n';
ans=min({ans, cnta, cntb});
}
cout<<ans;
}
/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |