Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
35
Task/Magic-constant/Pascal-P/magic-constant.pas
Normal file
35
Task/Magic-constant/Pascal-P/magic-constant.pas
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
program magicconstant(output);
|
||||
(* Magic constant *)
|
||||
|
||||
var
|
||||
n: integer;
|
||||
e: real;
|
||||
|
||||
(* returns the magic constant of a magic square of order n + 2 *)
|
||||
function a(n: integer): integer;
|
||||
var
|
||||
n2: integer;
|
||||
begin
|
||||
n2 := n + 2;
|
||||
a := (n2 * ((n2 * n2) + 1)) div 2
|
||||
end;
|
||||
|
||||
(* returns the order of the magic square whose magic constant is at least x *)
|
||||
function inva(x: real): integer;
|
||||
begin
|
||||
inva := trunc(exp(ln((2.0 * x)) / 3) + 1)
|
||||
end;
|
||||
|
||||
begin
|
||||
e := 1.0;
|
||||
write('The first 20 magic constants are ');
|
||||
for n := 1 to 20 do
|
||||
write(a(n): 4, ' ');
|
||||
writeln;
|
||||
writeln('The 1,000th magic constant is ', a(1000));
|
||||
for n := 1 to 20 do
|
||||
begin
|
||||
e := e * 10;
|
||||
writeln('10^', n: 2, ': ', inva(e): 9);
|
||||
end
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue