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

AC pascal

Posted by qiuwenhua at 2012-08-21 16:46:48 on Problem 3518
var n,i:longint;
    flag:boolean;
function fp(n:longint):longint;
var f,ff:boolean;
    a,b:longint;
begin
  f:=true;
  a:=n;
  b:=n;
  while f do
  begin
    ff:=true;
    dec(a);
    for i:=2 to trunc(sqrt(a)) do
    if a mod i=0 then begin ff:=false;break; end;
    if ff then break;
  end;
  while f do
  begin
    ff:=true;
    inc(b);
    for i:=2 to trunc(sqrt(b)) do
    if b mod i=0 then begin ff:=false;break; end;
    if ff then break;
  end;
  fp:=b-a;
end;
begin
  readln(n);
  while n<>0 do
  begin
    flag:=true;
    for i:=2 to trunc(sqrt(n)) do
    if n mod i=0 then begin flag:=false; writeln(fp(n)); break; end;
    if flag then writeln('0');
    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