"The matter does not know the number" of "grandson Counts": Chinese remainder theorem

Source: Internet
Author: User

1#include <stdio.h>2 3 //4 //Wu Shuling5 //time: 2016, 04,6 //7 //"The grandson counts the" the " matter does not know the number" the question:8 //This is not known for its number, 33 of the remaining two, 55 of the remaining seven, 77 of the remaining two, ask the geometry of the matter? 9 //  Ten //According to test instructions we have the following equation groups: One //x=2%3---> x=3*k+2 A //x=3%5 - //x=2%7 - // the  -  - //Analytic method for solving - intAnalytical (floatM1,floatM2,floatM3,floatA1,floatA2,floatA3) + { -     floatx=0, k1=0.0, k2=0.0, k3=0.0; +      A      for(k1=0;; k1++){  atX=M1*K1+A1;//= x=3*k+2 -K2= (X-A2)/m2;//= k= (x-2)/3 -         if(k2== (int) K2)//determine if K2 is an integer -         { -k3= (X-A3)/m3; -             if(k3== (int) K3)//determine if K2 is an integer in                  Break; -         } to     } +     return(int) x; - } the  *  $ //The solution of Chinese remainder theoremPanax Notoginseng intChineseremaindertheorem (intM1,intM2,intM3,intA1,intA2,intA3) - { the     inti,x=0;  +     intm,m1,m2,m3; A     intY1,y2,y3; the      +M =m1*m2*m3; -m1=m2*m3; $M2=m1*m3; $M3=m1*m2; -y1=m1%M1; -y2=m2%m2; they3=m3%m3; -x= (a1*m1*y1+a2*m2*y2+a3*m3*y3)%M;Wuyi      the     returnx; - } Wu  -  About intMain () $ { -     //x=2%3 x=a1%m1 -     //x=3%5 x=a2%m2 -     //x=2%7 x=a3%m3 A     intm1=3, m2=5, m3=7; +     inta1=2, a2=3, a3=2; theprintf"analytic method: \nx=%d \ n", Analytical (M1,M2,M3,A1,A2,A3));  -printf"Chinese remainder theorem: \nx=%d \ n", Chineseremaindertheorem (M1,M2,M3,A1,A2,A3)); $     return 0; the}

"The matter does not know the number" of "grandson Counts": Chinese remainder theorem

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.