이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int vmax = 5e5;
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
int m,n,f;
int rez = 0;
int last[vmax + 5];
long long mask[vmax + 5];
bool coprime(int x, int y)
{
if(!x)
{
return (y == 1);
}
if(!y)
{
return (x == 1);
}
if(x==1 && y==1)
{
return true;
}
if((mask[x] & mask[y]) != 0)
{
return false;
}
return (last[x] != last[y]);
}
void solve(int x, int y, int s, int dir)
{
for(int i=1;i<=s;i++)
{
int xx = x + i * dx[dir];
int yy = y + i * dy[dir];
rez += coprime(xx - 1,yy - 1);
}
x = x + s * dx[dir];
y = y + s * dy[dir];
if(s==1)
{
return;
}
for(int i=1;i<=s/2;i++)
{
int xs = x + i * dx[dir] + i * dx[(dir + 3) % 4];
int ys = y + i * dy[dir] + i * dy[(dir + 3) % 4];
rez += coprime(xs - 1,ys - 1);
}
solve(x + (s / 2) * dx[dir] + (s / 2) * dx[(dir + 3) % 4], y + (s / 2) * dy[dir] + (s / 2) * dy[(dir + 3) % 4], s / 2, dir);
solve(x + (s / 2) * dx[dir] + (s / 2) * dx[(dir + 3) % 4], y + (s / 2) * dy[dir] + (s / 2) * dy[(dir + 3) % 4], s / 2, (dir + 3) % 4);
for(int i=1;i<=s/2;i++)
{
int xd = x + i * dx[dir] + i * dx[(dir + 1) % 4];
int yd = y + i * dy[dir] + i * dy[(dir + 1) % 4];
rez += coprime(xd - 1,yd - 1);
}
solve(x + (s / 2) * dx[dir] + (s / 2) * dx[(dir + 1) % 4], y + (s / 2) * dy[dir] + (s / 2) * dy[(dir + 1) % 4], s / 2, dir);
solve(x + (s / 2) * dx[dir] + (s / 2) * dx[(dir + 1) % 4], y + (s / 2) * dy[dir] + (s / 2) * dy[(dir + 1) % 4], s / 2, (dir + 1) % 4);
}
void precalc()
{
for(int i=2;i<=vmax;i++)
{
if(!last[i])
{
for(int j=i;j<=vmax;j+=i)
{
last[j] = i;
}
}
}
int cnt = 0;
for(int i=2;i<=vmax;i++)
{
if(!mask[i])
{
for(int j=i;j<=vmax;j+=i)
{
mask[j] += (1LL<<cnt);
}
++cnt;
}
if(cnt > 62)
{
break;
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef home
freopen("nr.in","r",stdin);
freopen("nr.out","w",stdout);
#endif // home
cin>>m>>n>>f;
precalc();
for(int i=1;i<=f;i++)
{
int x,y,s;
cin>>x>>y>>s;
rez += coprime(x - 1,y - 1);
solve(x,y,s,0);
}
cout<<rez<<'\n';
return 0;
}
# | 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... |