- 循环
- 2013-07-07 02:57:28 @
v1算法对了两个点...v2只对一个...
v1:
// Amphineko's Code
var
Base: Cardinal;
PartLength: Byte;
PartDiv: Cardinal;
function StackFunc(const Depth: Byte; const LastPart: Cardinal): Integer;
var
CurrentPart: Cardinal;
begin
CurrentPart := LastPart * Base mod PartDiv;
if CurrentPart = Base then
begin
StackFunc := Depth;
Exit;
end;
if Depth = 100 then
begin
StackFunc := -1;
Exit;
end;
StackFunc := StackFunc(Depth + 1, CurrentPart);
end;
procedure Prepare;
var
loop1: Byte;
begin
PartDiv := 1;
for loop1 := 1 to PartLength do
PartDiv := PartDiv * 10;
Base := Base mod PartDiv;
end;
begin
Readln(Base, PartLength);
Prepare;
Write(StackFunc(2, Base * Base mod PartDiv));
end.
v2:
// Amphineko's Code
var
Base: Cardinal;
PartLength: Byte;
PartDiv: Cardinal;
Lens: array [1..10] of Byte;
LenPos: Byte;
function JudgeRepeat: Boolean;
var
loop1: Byte;
begin
JudgeRepeat := False;
if (LenPos - 1) mod 2 = 0 then
begin
for loop1 := 1 to LenPos div 2 do
if Lens[loop1] <> (Lens[loop1 + LenPos div 2] div 2) then
Exit;
JudgeRepeat := True;
end;
end;
function JudgeFunc(const CurrentPart, Depth: Cardinal): Boolean;
begin
if CurrentPart = Base then
begin
Lens[LenPos] := Depth;
Inc(LenPos);
if LenPos > 2 then
begin
JudgeFunc := JudgeRepeat;
Exit;
end;
end;
JudgeFunc := False;
end;
function StackFunc(const Depth: Byte; const LastPart: Cardinal): Integer;
var
CurrentPart: Cardinal;
begin
CurrentPart := LastPart * Base mod PartDiv;
if JudgeFunc(CurrentPart, Depth) then
begin
StackFunc := Depth div 2;
Exit;
end;
if Depth = 400 then
begin
StackFunc := -1;
Exit;
end;
StackFunc := StackFunc(Depth + 1, CurrentPart);
end;
procedure Prepare;
var
loop1: Byte;
begin
PartDiv := 1;
for loop1 := 1 to PartLength do
PartDiv := PartDiv * 10;
Base := Base mod PartDiv;
LenPos := 1;
end;
begin
Readln(Base, PartLength);
Prepare;
Write(StackFunc(2, Base * Base mod PartDiv));
end.
6 条评论
-
倾城依回释梦落红空巷琳影 LV 7 @ 2016-05-18 19:19:40
ORZ
-
2016-02-03 19:20:06@
这么长,为何我不信
-
2015-08-29 14:56:22@
大神
-
2015-08-29 14:56:08@
额!
-
2014-08-13 15:20:12@
明显pascal
-
2014-07-28 14:54:30@
这是甚么语言
- 1