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

Common Board

Plaese help me with problem 1153 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Posted by Happy New Year! Russia. 6 Jan 2002 18:40
Ok, maybe this will help...(+)
Posted by Michael_Rybak 6 Jan 2002 19:07
I don't know what kind of problems can you have. All you have to do
is multiply given number by 2 and find the integer part of it's
square root. Finding sqrt may be as following: for example, we have
to find sqrt(1234). Then the root will have 2 digits. Let's find the
first(left) digit. If it's 9,8,7,6,5 or 4, then, when we multiply
this number by itself, we'll get >=8100,>=6400,..,>=1600. So, the
first digit should be 3, because then we get 900<=x<=1600. Now, doing
the same for the second digit, we find, that the integer part of sqrt
(1234) is 35.
The same, digit by digit, you have to find sqrt of any number. Maybe
your long arifmetics multiplying is not efficient? I could send you
my unit with long arifmetics if you want.

Hope this will help.
Good luck!
Re: I use the same algoritm but i get TL
Posted by Happy New Year! Russia. 6 Jan 2002 22:10
My code:

Program t1153;

Const MaxDig=1300;
      CanUse='0123456789';

Type BigInt=array[1..MaxDig]of byte;

Var  A,B,C,D      :BigInt;
     i,j,um,u,v,k :integer;
     t,p,lens     :integer;
     ch           :char;
     less         :boolean;

begin
 FillChar(A,SizeOf(A),0);
 j:=0;
 while not(EOLN) do begin
  read(ch);
  while (pos(ch,CanUse)=0)and(EOLN=false) do read(ch);
  if ch=#13 then break;
  if ch=#10 then break;
  j:=j+1;
  B[j]:=Ord(ch)-Ord('0');
 end;
 for i:=1 to j do A[MaxDig-j+i]:=B[i];
 lens:=j;
 FillChar(B,SizeOf(B),0);
 um:=0;
 for i:=MaxDig downto 1 do begin
  B[i]:=(A[i]*2+um) mod 10;
  um:=(A[i]*2+um) div 10;
 end;
 A:=B;
 FillChar(C,SizeOf(C),0);
 for k:=MaxDig-((lenS)div 2) to MaxDig do begin
  for i:=1 to 10 do begin
   C[k]:=i;
   FillChar(D,SizeOf(D),0);
   for u:=MaxDig downto MaxDig-((lenS)div 2)-1 do begin
    um:=0;
    for v:=MaxDig downto MaxDig-((lenS)div 2)-1 do begin
     j:=c[u]*c[v]+um+d[-MaxDig+u+v];
     d[-MaxDig+u+v]:=j mod 10;
     um:=j div 10;
     end;
   end;
   less:=true;
   for u:=(MaxDig-lens-2) to MaxDig do
    if d[u]>a[u] then begin less:=false;break; end else
    if d[u]<a[u] then break;
   if not(less) then break;
  end;
  C[k]:=C[k]-1;
 end;
 i:=1;
 while c[i]=0 do i:=i+1;
 for j:=i to MaxDig do write(c[j]);writeln;
end.

My e-mail: nsc2001@rambler.ru
An idea for you..(+)
Posted by Michael_Rybak 6 Jan 2002 22:43
I couldn't get AC with almost the same program as yours. Maybe the
following idea will help you.
You multiply digits a lot. Precalculate them - make an array
m[0..9,0..9], and m[i,j]:=i*j
And, a very important thing - you use mod and div for numbers
obviously not larger than 100 - precalculate these two functions to.

Hope you'll get AC!
Good luck!
Re: Thank you very much ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! I get AC !
Posted by Happy New Year! Russia. 6 Jan 2002 23:05
> I couldn't get AC with almost the same program as yours. Maybe the
> following idea will help you.
> You multiply digits a lot. Precalculate them - make an array
> m[0..9,0..9], and m[i,j]:=i*j
> And, a very important thing - you use mod and div for numbers
> obviously not larger than 100 - precalculate these two functions
to.
>
> Hope you'll get AC!
> Good luck!