PKU 3543 iChess

http://poj.org/problem?id=3543
黒と白のタイルの枚数が与えられる。
これを使って正方形のチェス盤を作るとき、作成可能な最大の辺のサイズを答えろというような問題。

あまりにやるだけすぎるので、ちょっと調べながら書いてみました。
fortranです。

program P3543
  
  implicit none
  integer ::b,w,s,t,tb,tw,ans
  read(*,*) b,w
  if (b>w) then
     t=b
     b=w
     w=t
  end if
  ans=0
  s=1
  do 
     tw=(s*s+1)/2
     tb=s*s-tw
     if (tw<=w .and. tb<=b)then
        ans=s
     else
        exit
     end if
     s=s+1
  end do

  if (ans==0) then
     write(*,'(A)')'Impossible'
  else
     write(*,'(I0)')ans
  end if
  
end program P3543