POJ1006、hdu1370

本文介绍了一个基于中国剩余定理解决特定数学问题的程序实现案例。通过暴力求逆元的方法,解决了三个不同周期事件同时发生的下一个时间点问题。代码采用C++编写,并通过循环寻找满足条件的逆元。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

思路:中国剩余定理。纯粹的用暴力求逆元。

 1 #include<iostream>
 2 #include<string.h>
 3 #include<string>
 4 #include<algorithm>
 5 #include<stdio.h>
 6 #include<iomanip>
 7 #include<cmath>
 8 #include<map>
 9 using namespace std;
10 void Find(int &x,int &y,int &z){
11     while(23*28*x%33!=1){
12         x++;
13     }
14     while(23*33*y%28!=1){
15         y++;
16     }
17     while(28*33*z%23!=1){
18         z++;
19     }
20 }
21 int main(){
22     int x,y,z;
23     x=y=z=1;
24     Find(x,y,z);
25     int p,e,i,d,times;
26     times=1;
27     //int T;
28     //cin>>T;  //hdu需要多这两行
29     while(cin>>p>>e>>i>>d){
30         if(p==-1&&e==-1&&i==-1&&d==-1){
31             break;
32         }
33         int ans=(z*33*28*p+y*23*33*e+x*23*28*i-d+23*28*33)%(28*23*33);
34         if(ans==0) ans=28*23*33;
35         cout<<"Case "<<times++<<": the next triple peak occurs in "<<ans<<" days."<<endl;
36     }
37     return 0;
38 }

 

转载于:https://www.cnblogs.com/ISGuXing/p/8451532.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值