比赛 20110725 评测结果 AAAAAAAAAA
题目名称 失落的神庙 最终得分 100
用户昵称 ZhouHang 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-07-25 10:43:15
显示代码纯文本
Program losttemple;
Const
	inf = 'losttemple.in';
	ouf = 'losttemple.out';
        oo = 5000003;

Type
        pointer = ^hash;
	hash = record
		data,ans : qword;
		next : pointer;
		  end;

Var
	a : array [0..5000010] of pointer;
	n : qword;


Procedure Insert(x,y : qword);
	Var
		tmp : qword;
		tmp2 : pointer;
	Begin
		tmp := x mod oo;
		tmp2 := a[tmp];
		if a[tmp]=nil then begin
				new(a[tmp]);
				a[tmp]^.data := x;
				a[tmp]^.ans := y;
				a[tmp]^.next := nil;
				end
			else begin
				repeat
					tmp2 := tmp2^.next;
				until tmp2=nil;
				new(tmp2);
				tmp2^.data := x;
				tmp2^.ans := y;
				tmp2^.next := a[tmp];
				a[tmp]^.next := tmp2;
				end;
	End;
	
Function Find(x : qword): qword;
	Var
		now : pointer;
		tmp : qword;
	Begin
		tmp := x mod oo;
		if a[tmp]=nil then exit(0);
		now := a[tmp];
		while now<>nil do
		  begin
			if now^.data=x then exit(now^.ans);
			now := now^.next;
		  end;
		exit(0);
	End;

Function anss(x: qword): qword;
	Var
		tmp,jj : qword;
	Begin
		jj := 0;
		tmp := Find(x div 2);
		if tmp=0 then jj := jj + anss(x div 2)
			else inc(jj,tmp);

		tmp := Find(x div 3);
		if tmp=0 then jj := jj + anss(x div 3)
			else inc(jj,tmp);

		tmp := Find(x div 5);
		if tmp=0 then jj := jj + anss(x div 5)
			else inc(jj,tmp);

		tmp := Find(x div 7);
		if tmp=0 then jj := jj + anss(x div 7)
			else inc(jj,tmp);

		Insert(x,jj);
		Exit(jj);

	End;

Begin
	Assign(input,inf); Reset(input);
	Assign(output,ouf); Rewrite(output);

	Insert(1,1); Insert(0,1);

	readln(n);

	if n<2 then writeln(1)
		else writeln(anss(n));

	Close(input); Close(output);
End.