Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我用欧拉函数做,不知为何wrong answer(付代码)

Posted by dfoierzwk at 2007-02-19 16:55:13 on Problem 2407
var
  n,total:longint;
  a:array[1..100] of longint;
  b:array[1..100] of longint;

procedure work;
var
  sum:double;
  i,j,m:longint;
begin
  fillchar(a,sizeof(a),0);
  fillchar(b,sizeof(b),0);
  m:=n;j:=0;
  for i:=2 to trunc(sqrt(n)) do
    begin
      if m mod i=0 then begin inc(j);a[j]:=i;while m mod i=0 do begin m:=m div i;inc(b[i]);end;end;
    end;
  if j=0 then total:=n-1
  else begin
  sum:=n;
  for i:=1 to j do
    begin
      sum:=sum*(1-1/a[i]);
    end;
  total:=round(sum);
  end;
end;

begin
  readln(n);
  while n<>0 do
    begin
      work;
      writeln(total);
      readln(n);
    end;
end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator