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 |
发一波福利#include<cstdio> #include<cstring> using namespace std; typedef long long ll; ll exgcd(ll a,ll b,ll &x,ll &y) { if(a==0) { x=0;y=1; return b; } else { ll d,tx,ty; d=exgcd(b%a,a,tx,ty); x=ty-(b/a)*tx; y=tx; return d; } } int main() { int t; for(int t=1;t;t++) { ll n;bool bk=true; ll b1,m1,b[4],m[4]; for(int i=1;i<=3;i++)scanf("%lld",&b[i]); scanf("%lld",&n); b1=b[1]; if(b1==-1&&b[2]==-1&&b[3]==-1&&n==-1)break; m1=23;m[2]=28;m[3]=33; b1%=23;b[2]%=28;b[3]%=33; for(int i=2;i<=3;i++) { ll A,B,K,d,x,y; A=m1;B=m[i];K=b[i]-b1; d=exgcd(A,B,x,y); x=x*(K/d); x=(x%(B/d)+(B/d))%(B/d); if(K%d!=0)bk=false; b1=m1*x+b1; m1=m1*m[i]/d; } printf("Case %d: the next triple peak occurs in ",t); if(bk==false)printf("-1 days.\n"); else { if(b1-n>0)printf("%lld days.\n",b1-n); else printf("%lld days.\n",b1-n+21252); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator