Cao Chong Pig

Source: Internet
Author: User

"Title description"
Since Cao Chong finished the elephant, Caocao began to fathom let son do some career, so sent him to Zhongyuan pig farm pig, but Cao Chong full not happy, so in the work so-so, there was a time when Caocao want to know the number of sows, so Cao Chong want to play Caocao a. For example, if there are 16 sows, if 3 pigsty are built, there is no place for the 1 pigs left. If you build 5 pigsty, but there are still 1 pigs, there is no place to go, and if you build 7 pigsty, there are 2 heads to go. You as Cao General's personal secretary of course to the accurate number of pigs to amid, what should you do?

Exercises

Very naked Chinese remainder theorem, can not be naked again ... (note with long long)

1 /*************2 Vijos 11643 by Chty4 2016.11.15 *************/6#include <iostream>7#include <cstdio>8#include <cstring>9#include <cstdlib>Ten#include <ctime> One#include <cmath> A#include <algorithm> - using namespacestd; -typedefLong Longll; thell N,ans,m (1), a[ the],m[ the]; - inline ll read () - { -ll x=0, f=1;CharCh=GetChar (); +      while(!isdigit (CH)) {if(ch=='-') f=-1; Ch=GetChar ();} -      while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar ();} +     returnx*F; A } at voidEXGCD (ll a,ll b,ll &x,ll &y) - { -     if(b==0) {x=1; y=0;return;} -EXGCD (b,a%b,x,y); -ll t=x;x=y;y=t-a/b*y; - } in intMain () - { to     //freopen ("cin.in", "R", stdin); +     //freopen ("Cout.out", "w", stdout); -n=read (); the      for(LL i=1; i<=n;i++) M[i]=read (), A[i]=read (), m*=M[i]; *      for(LL i=1; i<=n;i++) $     {Panax Notoginsengll x,y,mi=m/M[i]; - EXGCD (mi,m[i],x,y); theAns= (Ans+mi*x*a[i])%M; +     } A     if(ans<0) ans+=M; theprintf"%i64d\n", ans); +     return 0; -}

Cao Chong Pig

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.