Pagini recente » Profil Antonie21Daniel | Cod sursa (job #3196850) | Cod sursa (job #109431) | Cod sursa (job #3284677) | Cod sursa (job #344977)
Cod sursa(job #344977)
#include <stdio.h>
#include <vector>
using namespace std;
#define pb push_back
#define maxn 1010
#define maxm 670000
long n, i, j, k, m, ox, oy, modx, mody, xx, yy, x1, y1, x2, y2, ok, lc, l, nt;
long f[maxn][maxn], cx[maxn*maxn], cy[maxn*maxn], co[maxn*maxn];
long v[maxn][maxn], sol[maxm], sx[maxn], sy[maxn];
vector<long> vx[maxn][maxn], vy[maxn][maxn];
int main()
{
freopen("robotei.in", "r", stdin);
freopen("robotei.out", "w", stdout);
scanf("%d%d%d%d%d%d%d%d", &n, &m, &xx, &yy, &modx, &mody, &ox, &oy);
for(i=0; i<modx; i++)
{
sx[i]=(n-1-i)/modx+1;
}
for(i=0; i<mody; i++)
{
sy[i]=(n-1-i)/mody+1;
}
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
v[i][j]=sx[i]*sy[j];
x1=(i*i+ox)%modx;
y1=(j*j+oy)%mody;
vx[x1][y1].pb(i);
vy[x1][y1].pb(j);
}
}
x1=xx;
y1=yy;
lc=1;
while(f[x1][y1]==0)
{
f[x1][y1]=lc;
x2=(x1*x1+ox)%modx;
y2=(y1*y1+oy)%mody;
x1=x2;
y1=y2;
++lc;
}
if(x1==xx && y1==yy)
{
ok=1;
lc--;
}
else return 1;
if(lc==0) return 1;
l=1;
memset(f, 0, sizeof(f));
cx[1]=xx;
cy[1]=yy;
co[1]=0;
f[xx][yy]=1;
for(i=1; i<=l; i++)
{
x1=cx[i];
y1=cy[i];
for(j=0; j<vx[x1][y1].size(); j++)
{
x2=vx[x1][y1][j];
y2=vy[x1][y1][j];
if(f[x2][y2]==0)
{
// printf("*");
f[x2][y2]=1;
cx[++l]=x2;
cy[l]=y2;
co[l]=co[i]+1;
}
}
nt=0;
if(co[i]<=m)
{
if(co[i]==0) nt=0;
nt=1;
if(ok)
{
nt+=((m-co[i])/lc);
}
}
sol[nt]+=v[x1][y1];
}
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if(f[i][j]==0)
{
sol[0]+=v[i][j];
}
}
}
for(i=0; i<=m; i++)
{
if(sol[i]>0)
{
printf("%d %d\n", i, sol[i]);
}
}
return 0;
}