PKU poj 1006 biorhythms (China residue theorem)

Source: Internet
Author: User

 

China Remainder Theorem

X = AI (mod mi) AI and MI are a group of numbers, and MI are mutually dependent, X

Make MI = m1 * m2 *~ MK, where Mi is not included.

Because Mi is mutually qualitative, there are X and Y,

St mi * Xi + Mi * Yi = 1

 

For Ei = mi * XI, the following conditions are available:

 

Then e0a0 + e1a1 + e2a2 + ~ + En-1 * an-1 is a solution of the equation.

 

Because n % 3 = 2, N % 5 = 3, N % 7 = 2 and 3, 5, 7
So that 5 × 7 is divided by 3 and 1, with 35 × 2 = 70;
So that 3 × 7 is divided by 5 to 1, and 21 × 1 = 21;
So that 3 × 5 is divided by 7 and 1, with 15 × 1 = 15.
(70 × 2 + 21 × 3 + 15 × 2) % (3 × 5 × 7) = 23

Similarly, this question should also be:
Divide 33 × 28 by 23 and divide 1 by 33 × 28 × 8 = 5544;
Divide 23 × 33 by 28 and divide 1 by 23 × 33 × 19 = 14421;
So that 23 × 28 is divided by 33 and 1, with 23 × 28 × 2 = 1288.
(5544 × P + 14421 × E + 1288 × I) % (23 × 28 × 33) = N + d
N = (5544 × P + 14421 × E + 1288 × I-d) % (23 × 28 × 33)

#include<stdio.h>#define P 5544#define E 14421#define I 1288#define ans 21252int main(void){    int p,e,i,d;    int n,num=0;    while(scanf("%d%d%d%d",&p,&e,&i,&d))    {        if(p==-1) return 0;        n=(P*p+E*e+I*i-d+ans)%ans;        if(n==0) n=ans;        printf("Case %d: the next triple peak occurs in %d days.\n",++num,n);    }    return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.