Smallest square that begins with n: Difference between revisions

no edit summary
(added Arturo)
No edit summary
Line 1,257:
| style="text-align:right" | 5041
|}
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
function LowSquareStartN(N: byte): integer;
{Find lowest square that matches N}
var S: string;
var T,J,DR,DN,DX: integer;
begin
{Get number of digits in N}
DN:=NumberOfDigits(N);
for Result:=1 to High(Integer) do
begin
T:=Result*Result;
{Divide off digits so no bigger than N}
DR:=NumberOfDigits(T);
DX:=DR-DN;
for J:=1 to DX do T:=T div 10;
{Does it match}
if T=N then break;
end;
end;
 
 
 
procedure SquareStartsN(Memo: TMemo);
{Find smallest square that begins with N}
var I,T: integer;
begin
for I:=1 to 50-1 do
begin
T:=LowSquareStartN(I);
Memo.Lines.Add(IntToStr(I)+' '+IntToStr(T*T));
end;
end;
 
</syntaxhighlight>
{{out}}
<pre>
1 1
2 25
3 36
4 4
5 529
6 64
7 729
8 81
9 9
10 100
11 1156
12 121
13 1369
14 144
15 1521
16 16
17 1764
18 1849
19 196
20 2025
21 2116
22 225
23 2304
24 2401
25 25
26 2601
27 2704
28 289
29 2916
30 3025
31 3136
32 324
33 3364
34 3481
35 35344
36 36
37 3721
38 3844
39 3969
40 400
41 41209
42 4225
43 4356
44 441
45 45369
46 4624
47 4761
48 484
49 49
Elapsed Time: 105.599 ms.
 
</pre>
 
 
=={{header|F_Sharp|F#}}==
465

edits