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

Why I got WA?

Posted by awts at 2003-05-27 18:36:14 on Problem 1142
here's my code:
const
     max = 35000;
var
   n,k,sum,t : longint;
   p : array[1..max div 2] of longint;
   num : array[1..max div 2] of integer;
function digits(i : longint) : integer;
var
   r : integer;
begin
     r := 0;
     while i > 0 do
     begin
          inc(r,i mod 10);
          i := i div 10;
     end;
     digits := r;
end;
function check : boolean;
var
   i,k : longint;
   sum : integer;
begin
     sum := digits(n);
     k := n;
     i := 1;
     check := false;
     while p[i] <= sqrt(k) do
     begin
          while k mod p[i] = 0 do
          begin
               k := k div p[i];
               dec(sum,num[i]);
          end;
          inc(i);
          if sum < 0 then exit;
     end;
     if (k = n) or ((k = 1) and (sum <> 0)) or (sum <> digits(k))
      then exit;
     check := true;
end;
procedure gen;
begin
     repeat
       inc(n);
     until check;
     writeln(n);
end;
function prime(k : longint) : boolean;
var
   i : integer;
begin
     prime := false;
     for i := 1 to t do
      if k mod p[i] = 0 then exit
       else
        if sqrt(k) < p[i] then break;
     prime := true;
end;
procedure init;
var
   i : longint;
begin
     p[1] := 2;
     t := 1;
     num[1] := 2;
     for I := 3 to max do
      if prime(I) then
      begin
           inc(t);
           p[t] := i;
           num[t] := digits(i);
      end;
end;
begin
     init;
     read(n);
     while  n > 0 do
     begin
          gen;
          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