| ||||||||||
| 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 | |||||||||
请教!用中国剩余定理求days时这段代码是WA的 (M1等定义为全局了)
int Biorhythms(int p,int e,int i,int d)
{
int y1,y2,y3,day;
y1=y2=y3=1;
while((y1*M1-1)%a!=0)
y1++;
while((y2*M2-1)%b!=0)
y2++;
while((y3*M3-1)%c!=0)
y3++;
day = (p*y1*M1 + e*y2*M2 + i*y3*M3)%21252;
if(day==0) day = 21252;
return (day - d + 21252)%21252;
}
但是稍稍改动一下后却是AC
int Biorhythms(int p,int e,int i,int d)
{
int y1,y2,y3,day;
y1=y2=y3=1;
while((y1*M1-1)%a!=0)
y1++;
while((y2*M2-1)%b!=0)
y2++;
while((y3*M3-1)%c!=0)
y3++;
day = (p*y1*M1 + e*y2*M2 + i*y3*M3 -d + 21252)%21252;
if(day==0) day = 21252;
return day;
}
有谁能解释一下吗,thanks in advance。
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator