## bzoj 2705 数学 欧拉函数

/**************************************************************
Problem: 2705
Language: Pascal
Result: Accepted
Time:12 ms
Memory:228 kb
****************************************************************/

var
n                           :longint;
i                           :longint;
pi                          :array[0..510] of longint;
cur                         :longint;
ans                         :int64;

function phi(x:longint):longint;
var
i                           :longint;
begin
cur:=x;
phi:=x;
for i:=2 to trunc(sqrt(x)) do
begin
if cur mod i=0 then
begin
phi:=(phi div i)*(i-1);
while cur mod i=0 do cur:=cur div i;
if cur=1 then break;
end;
if cur=1 then break;
end;
if cur<>1 then phi:=(phi div cur)*(cur-1);
end;

begin
for i:=1 to trunc(sqrt(n)) do
begin
if n mod i=0 then
begin
inc(pi[0]);
pi[pi[0]]:=i;
if n div i<>i then
begin
inc(pi[0]);
pi[pi[0]]:=n div i;
end;
end;
end;
ans:=0;
for i:=1 to pi[0] do
ans:=ans+int64(pi[i]*phi(n div pi[i]));
writeln(ans);
end.

posted on 2013-12-23 20:41  BLADEVIL  阅读(220)  评论(0编辑  收藏  举报