ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1066. Garland

My O(1) solution
Posted by Wang Xiang 27 Jul 2009 20:31
And,here it is:

program wx;
  var i,j,k,m,n:longint;
      b,c,s,t:extended;
  begin
    readln(n,c);
    dec(n);
    m:=trunc(sqrt(c));
    if m>=n then
      begin
        writeln('0.00');
        exit;
      end;
    if c/m<=m+1 then
      begin
        b:=m+c/m;
        s:=n*n-b*n+c;
      end
    else s:=1e100;
    inc(m);
    if c/m>=m-1 then
      begin
        b:=m+c/m;
        t:=n*n-b*n+c;
      end
    else t:=1e100;
    if s<t then writeln(s:0:2)
      else writeln(t:0:2);
  end.