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 |
Re:刚学完初等数论额!!!In Reply To:刚学完初等数论额!!! Posted by:jean890915 at 2011-10-10 16:00:40 > 看到这道题,兴奋啊!试试 过了额 //中国剩余定理,根据前段时间写的初等数论中程序改编 #include "iostream" using namespace std; typedef struct node { int data; //除数 int plus;//余数 int data1;//衍数 int data2;//乘率 int sum;//各总 }number_union; int main() { int i,j,sum=1,total=0,num=1,day; //sum最小公倍数,total答数 number_union a[3]; a[0].data = 23; a[1].data = 28; a[2].data = 33; for (i=0;i<3;i++) { cin>>a[i].plus; //余数 } while(a[0].plus!=-1 && a[1].plus!=-1 && a[2].plus!=-1) { total=0;sum=1; //初始化 for (i=0;i<3;i++) { sum*=a[i].data; //最小公倍数 } for (i=0;i<3;i++) { a[i].data1=sum/(a[i].data); for (j=1;j<a[i].data;j++) { if (j*a[i].data1%a[i].data==1) { a[i].data2=j; } } a[i].sum=a[i].data1*a[i].data2*a[i].plus; total+=a[i].sum; } total=total%sum; cin>>day; cout<<"Case "<<num<<": "; if (total == 0) total = 21252; if (total>day) cout<<"the next triple peak occurs in "<<total-day<<" days."<<endl; else if (total<day) cout<<"the next triple peak occurs in "<<total+21252-day<<" days."<<endl; else cout<<"the next triple peak occurs in "<<21252<<" days."<<endl; for (i=0;i<3;i++) { cin>>a[i].plus; //余数 } num++; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator