Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
报告队长:没看出来In Reply To:Why I got WA? Posted by:awts at 2003-05-27 18:36:14 > 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator