This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
long long bitmask[50005];
int mmare[50005];
int dl[]={-1,-1,0,1,1,1,0,-1};
int dc[]={0,1,1,1,0,-1,-1,-1};
bool prime(int x,int y)
{
if (x==1||y==1)
{
return true;
}
if (x==0||y==0)
{
return false;
}
if (bitmask[x]&bitmask[y])
{
return false;
}
if (mmare[x]==mmare[y]&&mmare[y]>1)
{
return false;
}
return true;
}
long long sum=0;
void fractal(int x,int y,int lung,int dir,int jum)
{
if (lung==0)
{
return;
}
int i;
for (i=1;i<=lung;i++)
{
x=x+dl[dir];
y=y+dc[dir];
sum=sum+prime(x,y);
}
if (jum==1)
{
lung=lung/2;
}
fractal(x,y,lung,(dir+1)&7,1-jum);
fractal(x,y,lung,(dir-1)&7,1-jum);
}
bool c[50005];
int n,m,frac,i,j,nr,x,y,numar;
int main()
{
cin>>n>>m>>frac;
nr=-1;
int lim=max(n,m);
for (i=2;i<=lim;i++)
{
if (mmare[i]==0)
{
for (j=i;j<=lim;j+=i)
{
mmare[j]=i;
}
}
}
for (i=2;i*i<=lim;i++)
{
if (bitmask[i]==0)
{
nr++;
for (j=i;j<=lim;j+=i)
{
bitmask[j]+=(1<<nr);
}
}
}
for (i=1;i<=frac;i++)
{
cin>>x>>y>>numar;
x--;
y--;
sum=sum+prime(x,y);
fractal(x,y,numar,0,1);
}
cout<<sum;
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... |