| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
秒过 =。= /* Ax=K+By > Ax-By=K*/
A=a;B=b;K=c;
d=exgcd(A,B,x,y);
if(K%d==0)
{
X=(x*(K/d)%(B/d)+B/d)%(B/d);
Y=(A*X-K)/B;
if(ans>(X+Y)&&X>=0&&Y>=0)
{
ans=X+Y;
ax=X;
ay=Y;
}
Y=(y*(K/d)%(A/d)+A/d)%(A/d);
X=(K-B*Y)/A;
if(ans>(X+Y)&&X>=0&&Y>=0)
{
ans=X+Y;
ax=X;
ay=Y;
}
}
/* By-Ax=K */
A=a;B=b;K=c;
d=exgcd(A,B,x,y);
if(K%d==0)
{
X=(x*(K/d)%(B/d)+B/d)%(B/d);
Y=(K+A*X)/B;
if(ans>(X+Y)&&X>=0&&Y>=0)
{
ans=X+Y;
ax=X;
ay=Y;
}
Y=(y*(K/d)%(A/d)+A/d)%(A/d);
X=(B*Y-K)/A;
if(ans>(X+Y)&&X>=0&&Y>=0)
{
ans=X+Y;
ax=X;
ay=Y;
}
}
if(ans==0x7FFFFFFFFFFFFFF)printf("no solution\n");
else printf("%I64d %I64d\n",ax,ay);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator