ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1118. Nontrivial Numbers

wa9. help please
Posted by Rustam 24 Apr 2008 17:42
here is my code. what's wrong with my program?please give me some tests. thx
program z1118_1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
i,n:longint;
k:longint;
function simple(n:longint):boolean;
var i:longint;
begin
 result:=true;
 if n=2 then exit;
 result:=false;
 for i:=2 to trunc(sqrt(n)) do
  if n mod i=0 then exit;
 result:=true;
end;
begin
 read(n,k);
 if k>n then
  begin
   i:=k;
   k:=n;
   n:=i;
  end;
 if (n<=1) and (k>=1) then
  begin
   write(1);
   halt(0);
  end;
 if n=k then
  begin
   write(k);
   halt(0);
  end;
 for i:=k downto n do
  if simple(i) then
   begin
    write(i);
    halt(0);
   end;
 for i:=n to k do
  if i mod 2=1 then
   begin
    write(i);
    halt(0);
   end;
 halt(0);
end.