Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

您的代码过于冗长了,贴一个我 AC 了的吧

Posted by IceKingdom at 2009-07-20 11:58:02 on Problem 2115 and last updated at 2009-07-20 11:58:35
In Reply To:哪位路过的帮忙看看,why!!!WA Posted by:_smiling at 2008-10-31 16:19:09
var     a , b , c , k
                : int64 ;
                
function        exgcd (a , b : int64 ; var x , y : int64) : int64 ;
var     t       : int64 ;
begin
        if (b = 0) then begin
         exgcd := a ;
         x := 1 ;
         y := 0 ;
        end
        else begin
         exgcd := exgcd (b , a mod b , x , y) ;
         t := x ;
         x := y ;
         y := t - (a div b) * y ;
        end ;
end ;
                
procedure       solve ;
var     u , v , x , y , d , g , tmp
                : int64 ;
begin
        u := c ;
        v := int64 (1) shl k ;
        d := b - a ;
        g := exgcd (u , v , x , y) ;
        if (d mod g <> 0) then
         writeln ('FOREVER')
        else begin
         x := x * d div g ; tmp := v div g ;
         x := x mod tmp ;
         if (x < 0) then inc (x , tmp) ;
         writeln (x) ;
        end ;
end ;

begin
    //    assign (input , 't2115.in') ; reset (input) ;
     //   assign (output , 't2115.out') ; rewrite (output) ;
        
        while (not seekeof) do begin
         readln (a , b , c , k) ;
         if (a = 0) and (b = 0) and (c = 0) and (k = 0) then break ;
         solve ;
        end ;
        
    //    close (input) ; close (output) ;
end .

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator