//PascalABC.NET версия 3.4.0.1677 от 17.06.18
//Если программа не запускается, то обновите версию
const
input_file = 'Kon.in';
output_file = 'Kon.out';
type
TCell = class
public
x, y: integer;
constructor Create(coords: string);
begin
coords := coords.Trim().ToLower();
y := StrToInt(coords[2]);
x := ord(coords[1]) - ord('a') + 1;
end;
constructor Create(i, j: integer);
y := j;
x := i;
function IsDeskCell(): boolean;
Result := (x > 0) and (y > 0) and (x <= 8) and (y <= 8);
class function operator+(a, b: TCell): TCell;
Result := new TCell(a.x + b.x, a.y + b.y);
class function operator=(a, b: TCell): boolean;
Result := (a.x = b.x) and (a.y = b.y);
function ToString: string; override;
Result := Format('({0}, {1})', x, y);
procedure PrintAnswer(path: List<TCell>);
var f := OpenWrite(output_file);
Writeln(f, path.Count() - 1);
Println(path.Count() - 1);
Println(path);
f.Close();
var knight_steps := Arr(
new TCell(1, 2),
new TCell(2, 1),
new TCell(2, -1),
new TCell(1, -2),
new TCell(-1, -2),
new TCell(-2, -1),
new TCell(-2, 1),
new TCell(-1, 2)
);
// var f := OpenWrite(input_file);
// Writeln(f, 'a1');
// Writeln(f, 'b2');
// f.Close();
// Exit;
var f := OpenRead(input_file);
var pawn_place: TCell := new TCell(f.ReadlnString());
var knight_place: TCell := new TCell(f.ReadlnString());
var paths := new List<List<TCell>>();
var occupied_cells := new List<TCell>();
paths.Add(Seq(knight_place).ToList);
occupied_cells.Add(knight_place);
repeat
var new_paths := new List<List<TCell>>();
foreach var path in paths do
foreach var step in knight_steps do
var p := new List<TCell>(path);
var t := p.Last + step;
if t.IsDeskCell() and not occupied_cells.Contains(t) then begin
p.Add(t);
new_paths.Add(p);
occupied_cells.Add(t);
if t = pawn_place then begin
PrintAnswer(p);
Exit;
paths := new_paths;
until (false)
end.
/// PascalABC.Net 3.4.2, 2053(11.05.19)
var
a, n: longint;
text: textfile;
function myMod(num, power, divider: longint): longint;
rest, i: longint;
rest:=1;
divider := abs(divider);
for i := 1 to power do
rest := rest * num;
rest := rest mod divider;
myMod := rest;
assign(text, 'input.txt');
{rewrite(text);
writeln(text, 109);
close(text);}
reset(text);
read(text, a);
writeln('a=', a);
close(text);
n := 1;
n := n + 1;
until MyMod(n, n, a) = 0;
assign(text, 'output.txt');
rewrite(text);
writeln(text, n);
{reset(text);
read(text, n);
writeln('n=', n);
//PascalABC.NET версия 3.4.0.1677 от 17.06.18
//Если программа не запускается, то обновите версию
const
input_file = 'Kon.in';
output_file = 'Kon.out';
type
TCell = class
public
x, y: integer;
constructor Create(coords: string);
begin
coords := coords.Trim().ToLower();
y := StrToInt(coords[2]);
x := ord(coords[1]) - ord('a') + 1;
end;
constructor Create(i, j: integer);
begin
y := j;
x := i;
end;
function IsDeskCell(): boolean;
begin
Result := (x > 0) and (y > 0) and (x <= 8) and (y <= 8);
end;
class function operator+(a, b: TCell): TCell;
begin
Result := new TCell(a.x + b.x, a.y + b.y);
end;
class function operator=(a, b: TCell): boolean;
begin
Result := (a.x = b.x) and (a.y = b.y);
end;
function ToString: string; override;
begin
Result := Format('({0}, {1})', x, y);
end;
end;
procedure PrintAnswer(path: List<TCell>);
begin
var f := OpenWrite(output_file);
Writeln(f, path.Count() - 1);
Println(path.Count() - 1);
Println(path);
f.Close();
end;
begin
var knight_steps := Arr(
new TCell(1, 2),
new TCell(2, 1),
new TCell(2, -1),
new TCell(1, -2),
new TCell(-1, -2),
new TCell(-2, -1),
new TCell(-2, 1),
new TCell(-1, 2)
);
// var f := OpenWrite(input_file);
// Writeln(f, 'a1');
// Writeln(f, 'b2');
// f.Close();
// Exit;
var f := OpenRead(input_file);
var pawn_place: TCell := new TCell(f.ReadlnString());
var knight_place: TCell := new TCell(f.ReadlnString());
f.Close();
var paths := new List<List<TCell>>();
var occupied_cells := new List<TCell>();
paths.Add(Seq(knight_place).ToList);
occupied_cells.Add(knight_place);
repeat
var new_paths := new List<List<TCell>>();
foreach var path in paths do
begin
foreach var step in knight_steps do
begin
var p := new List<TCell>(path);
var t := p.Last + step;
if t.IsDeskCell() and not occupied_cells.Contains(t) then begin
p.Add(t);
new_paths.Add(p);
occupied_cells.Add(t);
end;
if t = pawn_place then begin
PrintAnswer(p);
Exit;
end;
end;
end;
paths := new_paths;
until (false)
end.
/// PascalABC.Net 3.4.2, 2053(11.05.19)
var
a, n: longint;
text: textfile;
function myMod(num, power, divider: longint): longint;
var
rest, i: longint;
begin
rest:=1;
divider := abs(divider);
for i := 1 to power do
begin
rest := rest * num;
rest := rest mod divider;
end;
myMod := rest;
end;
begin
assign(text, 'input.txt');
{rewrite(text);
writeln(text, 109);
close(text);}
reset(text);
read(text, a);
writeln('a=', a);
close(text);
n := 1;
repeat
n := n + 1;
until MyMod(n, n, a) = 0;
assign(text, 'output.txt');
rewrite(text);
writeln(text, n);
close(text);
{reset(text);
read(text, n);
writeln('n=', n);
close(text);}
end.