Jump to content

Steady squares: Difference between revisions

Added Algol 60
(Added VTL-2)
(Added Algol 60)
Line 51:
<pre>
1 5 6 25 76 376 625 9376
</pre>
 
=={{header|ALGOL 60}}==
{{works with|GNU Marst|Any - tested with release 2.7}}
<syntaxhighlight lang="algol60">
begin comment find steady squares - numbers whose square ends in the number
e.g.: 376^2 = 141 376 ;
 
comment checks wheher n^2 mod p10 = n, i.e. n is a steady square
displays it if it is ;
procedure possibleSteadySuare ( n, p10 ); value n, p10
; integer n, p10
;
begin
integer m, n2;
n2 := n * n;
m := n2 - ( ( n2 % p10 ) * p10 ) ;
if m = n then begin
outinteger( 1, n )
end
end possibleSteadySquare ;
 
integer powerOfTen, p;
powerOfTen := 10;
 
comment note the final digit must be 1, 5 or 6 ;
for p := 0 step 10 until 10 000 do begin
if p = powerOfTen then begin
comment number of digits have increased ;
powerOfTen := powerOfTen * 10
end;
possibleSteadySuare( p + 1, powerOfTen );
possibleSteadySuare( p + 5, powerOfTen );
possibleSteadySuare( p + 6, powerOfTen )
end
end
</syntaxhighlight>
{{out}}
<pre>
1 5 6 25 76 376 625 9376
</pre>
 
3,021

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.