POJ 2891 Strange to Express integers 2012-09-05

Source: Internet
Author: User

http://poj.org/problem?id=2891

Solutions to linear equations.

Compared to the pit father, the data is relatively large, easily overflow.

1 Program poj2891;2 3 varM:int64;4 5Ar:Array[1..30000000] ofInt64;6 7 Ans,x,y,lcm:int64;8 9 Ten Procedure init; One  A  varI,j:longint; -  -   begin the  -m:=0; -  - Readln (m); +  -         fori:=1  toM Do +  A readln (A[i],r[i]); at  -   End; -  -  -Function EXTENDED_GCD (A,b:int64;varX,y:int64): Int64; -  in  varK:int64; -  to   begin +  -       ifb=0  Then begin the  *extended_gcd:=A; $ Panax Notoginsengx:=1; y:=0; -  the                   End +  A              Else begin the  +EXTENDED_GCD:=EXTENDED_GCD (b,aMoDb,x,y); -  $K:=x;x:=y;y:=k-(ADivb) *y; $  -                   End; -  the   End; - Wuyi  the Procedure Print (ans:int64); -  Wu   begin -  About writeln (ans); $  -   End; -  -  A Procedure main; +  the  varI:longint; -  $ D,ai,ri,k:int64; the  the   begin the  theans:=0; -  inai:=a[1];ri:=r[1]; the  the       fori:=2  toM Do About  the       begin the  thed:=EXTENDED_GCD (ai,a[i],x,y); +  -Lcm:=a[i]*aiDivD; the Bayi           if(R[i]-ri)MoDD<>0  Then beginPrint (-1); exit;End; the  theK:= ((xMoDA[i]) * (R[i]-ri)MoDA[i])DivD //This surplus is very important, no words will overflow, in this WA for a long time -  -Ri:= ((ri+ai*k)MoDLCM+LCM)MoDLCM; the  theai:=LCM; the  the       End; -  the print (RI); the  the   End;94  the  the Begin the 98Assign (input,'input.in'); reset (input); About  -Assign (output,'Output.out'); rewrite (output);101 102           while  not(EOF) Do103 104           begin the 106 Init;107 108              ifM<>0  Thenmain;109  the           End;111  the Close (Input); close (Output);113  the End.

POJ 2891 Strange to Express integers 2012-09-05

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.