{$A+,B-,D+,E+,F-,G+,I+,L+,N+,O-,P-,Q-,R-,S+,T-,V+,X+,Y+}
{$M 4096,0,655360}
{
   SUITES DE FIBONACCI : CARACTERES DE DIVISIBILITE -
                         RECHERCHE DE GRANDS ENTIERS PREMIERS

   PROJET PLURIDISCIPLINAIRE D'ALGEBRE DE 1ERE ANNEE E.S.I.E.A :
   R‚alis‚ par Matthieu BRIAND classe 11
   Version graphique programm‚e par Scythale.

   Ce programme a pour but de faire un crible des entiers premiers … l'aide
   des propri‚t‚s des suites de Fibonacci.

   Cahier des charges :
          - Structure des tableaux : IMPLEMENTEE
          - Calcul et affichage de Fn : IMPLEMENTE
          - Algorithme naif de recherche d'un nombre Fn premier : IMPLEMENTE
          - Si n est premier alors Fn a des chances d'ˆtre premier :
            IMPLEMENTE
          - Utilisation de la propri‚t‚ des diviseurs premiers
            de la forme 4t+1 d'un terme d'indice premier :
            IMPLEMENTE
          - ChronomŠtrage des 3 algorithmes : IMPLEMENTE
          - Am‚liorations graphiques  : IMPLEMENTEES


   !!ATTENTION VERSION NON FINALISEE : PREVERSION DU 29 Mai 1995 !!



ÖÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ·
º                    Graphic Procedures programmed by XTech                  º
ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¶
º   Supplied by: XTech                ³ ³    Written by: XTech               º
º    Cracked by: None                 ³ ³    Protection: None                º
º   Packaged by: XTech                ³ ³Graphics/Sound: VGA                 º
º  Release Date: 15/05/95             ³ ³  Program Type: NetWork             º
º        Rating: 1                    ³ ³    # of Disks: 1                   º
ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¶
ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¶
º     Greets out to: - Akira , Yazz , Red Bird , Jermo, Ram , The CMB -      º
ÓÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ½}

Uses crt, dos, graph, bluegui_, ico_, mouse_, scroll, time;

type

  num = array[1..32000] of byte;

  numptr = record
            t:^num;
            s:integer;
           end;
var
    comb_  : array[0..4] of boolean;
    Result : boolean;
        wp : ViewPortType;


       err : integer;
       ind : longint;
      indx : longint;

     px,py : integer;
  pxm,pym,
   pxi,pyi : integer;
     tx,ty : integer;
{$i fading.pas}
{ÍÍÍÍÍÍ[ Initialisation de l'‚cran graphique]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ13/05/95Í}
procedure Init_BGI;
var Path: string;
  Error, Driver, Mode: integer;
begin

  Path := '\tp\bgi';
  repeat
    Driver := Detect;
    InitGraph( Driver, Mode, path );
    Error := GraphResult;
    if ( Error <> grOK ) then begin
        Writeln( 'Graphics ERROR ', GraphErrorMsg( Error ) );
        if ( Error = grFileNotFound ) then begin
          Write( 'Enter path to graphics driver: ');
          Readln( Path );
          end;
        end;
  until Error = grOK;
end;

{ÍÍÍÍÍÍ[ Barre de titre ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ13/05/95Í}
procedure barre_title(x1,y1,x2,y2:word;color:byte);
begin
 setfillstyle(SolidFill,color);
 bar(x1+1,y1+1,x2-1,y2-1);
{ setcolor(white);
 line(x1,y1,x2,y1);
 line(x1,y1,x1,y2);}
 setcolor(black);
 line(x1+1,y2,x2,y2);
 line(x2,y1+1,x2,y2);
end;

{ÍÍÍÍÍÍ[ Ecrit en relief et soulign‚]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ13/05/95Í}
procedure Ecrit_(x,y:word;mot:string;souligne:boolean);
var xxx:integer;
     mt:string;
 j,i,cl:integer;
begin
 mt:=mot;

 if pos('~',mot)>0 then
   delete(mot,pos('~',mot),1);

 cl:=getcolor;
 setcolor(black);
 outtextxy(x+1,y+1,mot);
 if souligne then
   line(x+1,y+2,x+textwidth(mot)+1,y+2);
 setcolor(cl);
 outtextxy(x,y,mot);
 if souligne then
   line(x,y+1,x+textwidth(mot),y+1);
 if pos('~',mt)>0 then
   begin
     setcolor(lightgreen);
     outtextxy(x+textwidth( copy(mot,1, pos('~',mt) -1) ),y,mot[pos('~',mt)]);
     line(x+textwidth( copy(mot,1, pos('~',mt) -1) ),y+9,x+textwidth( copy(mot,1, pos('~',mt) ) ),y+9);
   end;
 setcolor(cl);
end;

{ÍÍÍÍÍÍ[ Cadre de titre ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ13/05/95Í}
procedure cadre_title(x1,y1,x2,y2:word;color:byte;titre:string;t_c:byte);

begin
 setcolor(black);
 line(x1+6-1,y1-1,x1-1,y1-1);
 line(x1-1,y1-1,x1-1,y2+1);
 line(x1-1,y2+1,x2+1,y2+1);
 line(x2+1,y2+1,x2+1,y1-1);
 line(x2+1,y1-1,x1+6-1+6+textwidth(titre),y1-1);

 setcolor(color);
 line(x1+6,y1,x1,y1);
 line(x1,y1,x1,y2+1);
 line(x1,y2+2,x2+2,y2+2);
 line(x2+2,y2+2,x2+2,y1);
 line(x2,y1,x1+6+6+textwidth(titre),y1);

 setcolor(t_c);
 ecrit_(x1+10,y1-textheight(titre) div 2,titre,false);

end;

{ÍÍÍÍÍÍ[ Combo box off ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ13/05/95Í}
procedure combof(x1,y1:word;color:byte);
var
        a,b : byte;
    Losange : array[1..4] of PointType;
begin
 a:=12;

 Losange[1].x:=x1-(a div 2)+2;
 Losange[1].y:=y1;

 Losange[2].x:=x1;
 Losange[2].y:=y1-(a div 2)+2;

 Losange[3].x:=x1+(a div 2)-2;
 Losange[3].y:=y1;

 Losange[4].x:=x1;
 Losange[4].y:=y1+(a div 2)-2;

 Setcolor(couleur_ppale);
 SetFillStyle(SolidFill,couleur_ppale);
 FillPoly(SizeOf(Losange) div SizeOf(PointType), Losange);

 setcolor(black);
 line(x1+a div 2,y1,x1,y1+a div 2);
 line((x1+a div 2)+1,y1,x1+1,y1+a div 2);
 line(x1,y1+a div 2,x1-a div 2,y1);

 setcolor(light(couleur_ppale));
 line(x1-a div 2,y1,x1,y1-a div 2);
 line((x1-a div 2)-1,y1,x1-1,y1-a div 2);
 line(x1,y1-a div 2,x1+a div 2,y1);

end;

{ÍÍÍÍÍÍ[ Combo box on ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ13/05/95Í}
procedure combon(x1,y1:word;color:byte);
var
        a,b : byte;
    Losange : array[1..4] of PointType;
begin
 a:=12;

 Losange[1].x:=x1-(a div 2)+2+1;
 Losange[1].y:=y1;

 Losange[2].x:=x1;
 Losange[2].y:=y1-(a div 2)+2+1;

 Losange[3].x:=x1+(a div 2)-2-1;
 Losange[3].y:=y1;

 Losange[4].x:=x1;
 Losange[4].y:=y1+(a div 2)-2-1;

 Setcolor(couleur_ppale);
 SetFillStyle(SolidFill,white);
 FillPoly(SizeOf(Losange) div SizeOf(PointType), Losange);

{ relief interne
 setcolor(black);
 line(Losange[1].x-1-2,Losange[1].y,Losange[2].x,Losange[1].y-1-2);
 line(Losange[1].x-1-2,Losange[1].y,Losange[4].x,Losange[4].y+1+2);}

 setcolor(black);
 line(x1+a div 2,y1,x1,y1+a div 2);
 line((x1+a div 2)+1,y1,x1+1,y1+a div 2);
 line(x1,y1+a div 2,x1-a div 2,y1);

 setcolor(light(couleur_ppale));
 line(x1-(a div 2),y1,x1,y1-(a div 2));
 line(x1-(a div 2)-1,y1,x1-1,y1-(a div 2));
 line(x1,y1-(a div 2),x1+(a div 2),y1);

end;


procedure bk_gnd(x1,y1,x2,y2:word);
var p:pointer;
   wp:viewporttype;
   i,j:integer;
   size:word;
begin
  getviewsettings(wp);
  setviewport(x1,y1,x2,y2,clipoff);
  draw_ico('esea.ico',0,0);

  Size := ImageSize(0,0,31,31);
  GetMem(P, Size);   { Allocate memory on heap }
  GetImage(0,0,31,31, P^);

  for i:=0 to (x2-x1)div 32 do
   for j:=0 to (y2-y1)div 32 do
    PutImage(i*32,j*32,P^,NormalPut);

  with wp do
   setviewport(x1,y1,x2,y2,clip);

end;

{ÍÍÍÍÍÍ[ Dessine l'‚cran ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ13/05/95Í}
procedure Init_Screen;
begin
 couleur_ppale:=blue;
 couleur_light:=lightblue;
 cadre(0,0,getmaxX,GetmaxY,couleur_ppale);
{ Plaque de fond }
 plaque(5,5,getmaxx-5,getmaxy-5,couleur_ppale);

 barre_title(7,7,getmaxx-8,40,red);
 settextjustify(centertext,toptext);
 settextstyle(8,horizdir,3);
 setcolor(white);
 outtextxy(Succ(GetMaxX) div 2, 5, 'Crible des Grands Entiers Premiers' );
 outtextxy(GetMaxX-40, 5, 'v1.5' );
 settextjustify(lefttext,toptext);

 exicen(17,17);
 draw_ico('esiea.ico',40,8);

{ plaque de menu }
 plaque(7,43,150,getmaxy-8,couleur_ppale);

{ unit‚s
 settextstyle(defaultfont,horizdir,1);
 Cadre_title(10,50,150-3,47+32+6,couleur_light,'Lecteurs',white);


 draw_ico('A3pces.ico' ,9+3,55);
 draw_ico('B3pces.ico' ,9+32+20,55);
 draw_ico('CHDRIVE.ico',9+32+20+32+20,55);}

{ titre }
 settextstyle(Defaultfont,horizdir,1);
 Cadre_title(11,60+100-20,150-4,130+100,couleur_light,'Algorithme',white);
{ Boutons de choix }
{ 1 }
 combof(25,56+100,darkgray);
 setcolor(lightgray);
 Ecrit_(40,54+100,'S~ans calcul',false);

{ 2 }
 combof(25,76+100,darkgray);
 setcolor(lightgray);
 Ecrit_(40,74+100,'~Na‹f',false);
{ 3 }
 combof(25,96+100,darkgray);
 setcolor(lightgray);
 Ecrit_(40,94+100,'~Pseudo-Na‹f',false);
{ 4 }
 combof(25,116+100,darkgray);
 setcolor(lightgray);
 Ecrit_(40,114+100,'~Evolu‚',false);
{ Termes et boutons }
 text_input_box(11,150+100,150-7-2,couleur_ppale,'Terme',lightgray);

 draw_button(7+1,180+100,150-7-2,20,couleur_ppale,'Saisie ~Terme');

 draw_button(7+1,200+100+2,150-7-2,20,couleur_ppale,'Calcul ~Suivi');

 draw_button(7+1,220+100+4,150-7-2,20,couleur_ppale,'Calcul ~Final');

{ bk_gnd(153,45,getmaxx-7,getmaxy-20);}

 plaque(154,43,getmaxx-9,getmaxy-8,couleur_ppale);
 SetFillStyle(solidfill,black);
 bar(154+5,43+5,getmaxx-9-5,getmaxy-8-5);
 rect_relief_inf(154+5,43+5,getmaxx-9-5,getmaxy-8-5,couleur_ppale);
{ bk_gnd(154+5,43+5,getmaxx-9-5,getmaxy-8-5);}
 setcolor(lightgreen);
 ecrit_(7+4,420-10,'Progression',false);
draw_ratio_box(7+1+1,420,150-2,couleur_ppale);

end;

{ÍÍÍÍÍÍ[ GŠre les combo ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ13/05/95Í}
procedure combox(c:byte);
var i : integer;
begin
  Hide_Mouse;
  for i:=1 to 4 do
    comb_[i]:=false;
  comb_[c]:=true;

  if not (comb_[c]=false) then
      for i:=0 to 3 do
        if comb_[i+1] then
          combon(25,56+i*20+100,darkgray)
        else
          combof(25,56+i*20+100,darkgray);
  Show_Mouse;
  delay(40);
end;

{ÍÍÍÍÍÍ[ Procedures math‚matiques ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ17/05/95Í}
procedure OT(s:string;ret:boolean);
begin

 if ((px+textwidth(s))>=pxm) and not ret then
  begin
   inc(py,ty+4);
   px:=pxi;
  end;

 if px>=pxm then
  begin
   inc(py,ty+4);
   ret:=false;
   px:=pxi;
  end;

 if (py+ty)>=pym then
  begin
   scroll_up(pxi+1,pyi+tx+4,pxm-pxi-2,pym-pyi-12,tx+4);
   setfillstyle(solidfill,black);
   bar(pxi,pym-tx-4,pxm-1,pym-1);
   py:=pym-tx-4-2;
  end;

 if ret then
  begin
   inc(py,ty+4);
   ret:=false;
   outtextxy(px+3,py,s);
   px:=pxi;
  end
 else
  begin
   outtextXY(px,py,s);
   inc(px,textwidth(s));
  end;


end;

procedure show(ptr:numptr);
var i:integer;
    s:string;
begin
 for i:=ptr.s downto 1 do
  begin
    str(ptr.t^[i],s);
    OT(s,false);
  end;

end;

procedure init_(var ptr:numptr);
var i:integer;
begin
 for i:=1 to 32000 do
   ptr.t^[i]:=0;
 ptr.t^[1]:=1;
 ptr.s:=1;

end;

procedure init_0(var ptr:numptr);
var i:integer;
begin
 for i:=1 to 32000 do
   ptr.t^[i]:=0;
 ptr.s:=0;

end;

function est_nul(ptr:numptr):boolean;
var i:integer;
begin
  if ptr.s=0 then
    est_nul:=true
  else
    est_nul:=false;

end;

function max(i,j:integer):integer;
begin
 if i>j then max:=i
 else
 max:=j;
end;

procedure add_c(var NA:numptr;cst:byte);
var ret:byte;
      i:integer;
      c:integer;
Begin

     ret:=0;
     for i:=1 to na.s+1 do
       begin
         if (i>1) then cst:=0;

         c:=NA.t^[i]+(cst+ret);

         ret:=0;
         if (c>=10) then
           begin
             ret:=1;
             c:=c-10;
           end;

         NA.t^[i]:=c;

         if ret=0 then
         begin
           if (na.s<i) then
             if (NA.t^[i]<>0) then inc(NA.s);

           exit;
         end;

       end;
    if (NA.t^[na.s+1]<>0) then inc(NA.s);

end;


procedure add(var NA,NB,ND:numptr);
var ret:byte;
      i:integer;
      c:integer;
Begin

     ret:=0;
     for i:=1 to max(na.s,nb.s)+1 do
       begin
         c:=NA.t^[i]+NB.t^[i]+ret;
         ret:=0;
         if c>=10 then
           begin
             ret:=1;
             c:=c-10;
           end;
         ND.t^[i]:=c;

       end;
    if (ND.t^[i]<>0) then ND.s:=i
     else if (i>1) and (ND.t^[i-1]<>0) then ND.s:=i-1;

end;


function greater(NA,NB:numptr):boolean;
var ret:byte;
      i:integer;
      c:integer;
Begin

  if NA.s>NB.s then
    greater:=true
  else if NA.s<NB.s then
         greater:=false
    else
      begin
        i:=max(na.s,nb.s);
        while (NA.t^[i]=NB.t^[i]) and (i>0) do
          dec(i);
        if (NA.t^[i]>=NB.t^[i]) then
          greater:=true
        else
          greater:=false;
      end;

end;


procedure sous_c(var NA:numptr;cst:byte);
var ret:byte;
      i:integer;
      c:integer;
Begin
   ret:=0;
   if not est_nul(na) then
     for i:=1 to na.s do
       begin

         if i>1 then cst:=0;

         if (NA.t^[i]<(cst+ret)) and (i<na.s) then
           begin
             NA.t^[i]:=10+NA.t^[i]-(cst+ret);
             ret:=1;
           end
         else
           begin
             NA.t^[i]:=NA.t^[i]-(ret+cst);
             ret:=0;
             if (na.s=i) then
               if (i>0) and (NA.t^[i]=0) then dec(NA.s);
             exit;
           end

       end;

    if (NA.t^[i]<>0) then NA.s:=i
     else if (i>1) and (NA.t^[i-1]<>0) then NA.s:=i-1;

end;


function is_void(NA:numptr):boolean;
begin
     is_void := (NA.s=0) OR ( (NA.s=1) AND (NA.t^[1]=0) )
end;


procedure sous(var NA,NB,ND:numptr);
var ret:byte;
      i:integer;
      c:integer;
Begin
     ret:=0;
     for i:=1 to max(na.s,nb.s) do
       begin
         if (NA.t^[i]< (NB.t^[i]+ret) ) then
           begin
            ND.t^[i]:=10+NA.t^[i]-(NB.t^[i]+ret);
            ret:=1;
           end
         else
           begin
            ND.t^[i]:=NA.t^[i]-(NB.t^[i]+ret);
            ret:=0;
           end;

       end;

    if (ND.t^[i]<>0) then ND.s:=i
     else if (i>1) and (ND.t^[i-1]<>0) then ND.s:=i-1;
end;


function modulozero(var NA,NB:numptr):boolean;
var
 naa:numptr;
Begin
 new(Naa.t);
 init_0(Naa);
 add(NA,Naa,Naa);

 while greater(NAa,NB) do
   sous(NAa,NB,NAa);

 modulozero:= not (is_void(NAa));
 dispose(NAa.t);
end;


procedure div2(var NAA:numptr);
var t:numptr;
    m:longint;
    i:integer;
Begin
 m:=0;
 if (naa.s<=10) and (naa.t^[10]<=2) then
  begin
   for i:=naa.s downto 1 do
     m:=m*10+naa.t^[i];
   m:=m div 2;
   init_0(naa);
   i:=0;
   while (m<>0) do
    begin
      inc(i);
      naa.t^[i]:=m mod 10;
      m:=m div 10;
    end;
   naa.s:=i;
  end

 else
 begin
  new(t.t);
  init_0(t);

   repeat
    sous_c(NAA,2);
    add_c(t,1);
   until (NAA.s<=2) and (NAA.t^[1]<=1) and (NAA.t^[2]=0);

  init_0(NAA);
  add(NAA,t,NAA);

  dispose(t.t);
 end;

end;


Function INDICE_PREMIER (ENTIER: LongInt): Boolean;
Var
   I:      Integer;
   VALEUR: Boolean;

Begin
   (* Si l'indice n'est pas premier, alors le nombre de Fibonacci n'est pas premier *)
   VALEUR:=True;
   I:=2;
   While ( (I<=(ENTIER div 2)) and VALEUR ) do
         Begin
         if ENTIER mod I=0
         Then VALEUR:=False;
         I:=I+1;
         End;
   INDICE_PREMIER:=VALEUR;
End;


Function NAIF (NA:numptr): Boolean;
Var
   I:      Integer;
   VALEUR: Boolean;
   NBB:    numptr;
   deux:   numptr;

Begin
     new(deux.t);
     init_(deux);
     add(deux,deux,deux);          {super!!!! ca fait 2 }

     new(NBB.t);
     init_0(NBB);
     add(NA,NBB,NBB);

     (* Algorithme "naturel" qui teste tous les diviseurs jusqu'a N div 2! *)
     VALEUR:=True;
     div2(NBB);

     while (greater(NBB,deux) AND (VALEUR) ) do
       begin
         VALEUR:=modulozero(NA,NBB);
         sous_c(NBB,1);
       end;
     NAIF:=Valeur;
     dispose(NBB.t);
     dispose(deux.t);
End;


Function PSEUDONAIF (INDICE:longint; NA:numptr): Boolean;
Begin
     PSEUDONAIF := INDICE_PREMIER(INDICE) AND NAIF(NA)
End;



Function EVOLUE (INDICE:longint; NA:numptr): Boolean;
Var
    NAa: numptr;
    quatre:numptr;
    valeur:boolean;

Begin
     VALEUR:=False;
     new(quatre.t);
     init_(quatre);
     add(quatre,quatre,quatre);          {super!!!! ca fait 2! }
     add(quatre,quatre,quatre);          {mieux: ca fait 4!    }


     new(naa.t);
     init_0(naa);
     add(na,naa,naa);
     sous_c(naa,1);

     If INDICE_PREMIER(INDICE)
     then If not (modulozero (Naa,quatre) )
          then if NAIF(NA)
               then VALEUR:=True;

     dispose(naa.t);
     dispose(quatre.t);
     EVOLUE:=VALEUR;
End;

{ÍÍÍÍÍÍ[ Calcule le terme final ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ17/05/95Í}
procedure calcule_terme_f(ind:longint);
var
        fi : numptr;
        fj : numptr;
         s : string;
      indx : longint;
         t : longint;


begin
 t:=timer16;

 if (ind mod 2)=1 then ind:=ind-1;
 draw_ratio_box(7+1+1,420,150-2,couleur_ppale);

 text_input_box(7+1+1,450,150-2,couleur_ppale,'Temps : ',white);

 inc(py,ty);

 gotoxy(px,py);

 new(fi.t);
 new(fj.t);

 init_0(fi);
 init_(fj);

 indx:=ind;

 ind:=2;

 setcolor(white);


if (indx>1) then
while (ind<=indx) do
 begin

  add(fi,fj,fi);

 pct_done( ( (ind)*100) div indx);

  add(fi,fj,fj);

 inc(ind);

 pct_done( ( (ind)*100) div indx );

  inc(ind);

 end;
 pct_done(100);

 str(indx,s);
 s:='f('+s+')=';
 OT('',true);
 OT(s,false);
 show(fi);
 OT('',true);
 If (comb_[2] and naif(FI)) then
                           Begin
                             OT (' est premier (ALGO NAIF)',false);
                             OT('',true);
                           End;
 If (comb_[3] and pseudonaif(INDX,FI)) then
                           Begin
                             OT (' est premier (ALGO PSEUDO NAIF)',false);
                             OT('',true);
                           End;

 If (comb_[4] and evolue (INDX,FI) ) then
                           Begin
                             OT (' est premier (INDICE PREMIER+ forme 4t+1 +NB PREMIER)',false);
                             OT('',true);
                           End;

 inc(indx);

if (indx>1) then
 begin
  str(indx,s);
  s:='f('+s+')=';
  OT(s,false);
  show(fj);
  OT('',true);
  If ( comb_[2] and naif(FJ)) then
                           Begin
                             OT (' est premier (ALGO NAIF)',false);
                             OT('',true);
                           End;

 If (comb_[3] and pseudonaif(INDX,FJ)) then
                           Begin
                            OT (' est premier (INDICE PREMIER +NB PREMIER)',false);
                            OT('',true);
                           End;

 If (comb_[4] and evolue (INDX,FJ) ) then
                           Begin
                             OT (' est premier (INDICE PREMIER+ forme 4t+1 +NB PREMIER)',false);
                             OT('',true);
                           End;

 end;

 t:=(timer16-t) div 18;
 str(t,s);
 input_box(7+2+10+textwidth('Temps : '),450-5,150-2-3,white,s+' s');
 dispose(fi.t);
 dispose(fj.t);
 setviewport(0,0,getmaxx,getmaxy,clipoff);

end;

{ÍÍÍÍÍÍ[ Calcule le terme continu ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ17/05/95Í}
procedure calcule_terme_c(ind:longint);
var
        fi : numptr;
        fj : numptr;
         s : string;
      indx : longint;

begin

 draw_ratio_box(7+1+1,420,150-2,couleur_ppale);

 inc(py,ty);

 gotoxy(px,py);

 new(fi.t);
 new(fj.t);

 init_0(fi);
 init_(fj);

 indx:=ind;
 ind:=2;

 setcolor(white);

{ affiche F1 }
  s:='f(1)=1';
  OT('',true);
  OT(s,false);
  OT('',true);
  OT (' est premier (ALGO NAIF)',false);
  OT('',true);


if (indx>1) then
while (ind<=indx) do
 begin

  add(fi,fj,fi);
  pct_done( ( (ind)*100) div indx);

  add(fi,fj,fj);

 pct_done( ( (ind+1)*100) div indx);

{ affiche Fi }
  str(ind,s);
  s:='f('+s+')=';
  OT('',true);
  OT(s,false);
  show(fi);
  OT('',true);
 If (comb_[2] and naif(FI)) then
                           Begin
                             OT (' est premier (ALGO NAIF)',false);
                             OT('',true);
                           End;
 If (comb_[3] and pseudonaif(IND,FI)) then
                           Begin
                             OT (' est premier (INDICE PREMIER +NB PREMIER)',false);
                             OT('',true);
                           End;

 If (comb_[4] and evolue (IND,FI) ) then
                           Begin
                             OT (' est premier (INDICE PREMIER+ forme 4t+1 +NB PREMIER)',false);
                             OT('',true);
                           End;

 inc(ind);

{affiche Fj }
  str(ind,s);
  s:='f('+s+')=';
  OT(s,false);
  show(fj);
  OT('',true);
 If (comb_[2] and naif(FJ)) then
                           Begin
                             OT (' est premier (ALGO NAIF)',false);
                             OT('',true);
                           End;
 If (comb_[3] and pseudonaif(IND,FJ)) then
                           Begin
                             OT (' est premier (INDICE PREMIER +NB PREMIER)',false);
                             OT('',true);
                           End;

 If (comb_[4] and evolue (IND,FJ) ) then
                           Begin
                             OT (' est premier (INDICE PREMIER+ forme 4t+1 +NB PREMIER)',false);
                             OT('',true);
                           End;

 inc(ind);
  If (IND mod 2)=0 then Readkey;

 end;

if (indx=0) or (indx=1) then
 begin
{ affiche Fi }
  str(indx,s);
  s:='f('+s+')=';
  OT('',true);
  OT(s,false);
  show(fi);
  OT('',true);
 If (comb_[2] and naif(FI) ) then
                           Begin
                             OT (' est premier (ALGO NAIF)',false);
                             OT('',true);
                           End;
 If (comb_[3] and pseudonaif(INDX,FI)) then
                           Begin
                             OT (' est premier (INDICE PREMIER +NB PREMIER)',false);
                             OT('',true);
                           End;

 If (comb_[4] and evolue (INDX,FI) ) then
                           Begin
                             OT (' est premier (INDICE PREMIER+ forme 4t+1 +NB PREMIER)',false);
                             OT('',true);
                           End;
 end;

 dispose(fi.t);
 dispose(fj.t);
 setviewport(0,0,getmaxx,getmaxy,clipoff);

end;


{ÍÍÍÍÍÍ[ GŠre les commandes ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ13/05/95Í}
procedure Handle_Event;
Var
    Xso,Yso,
    oXso,oYso : Integer ;
    So1,So2,So3 : Boolean ;
         c : char;
begin
 comb_[1]:=true;
 comb_[2]:=false;
 comb_[3]:=false;
 comb_[4]:=false;
 combon(25,56+100,darkgray);

 Repeat
  Mouse_status ( So1 , So2 , So3 , Xso , Yso ) ;
  If So1 or So3 then
   begin
    If Clipsouris(Xso,Yso,7+1,180+100,150-7-2,20) or
       Clipsouris(Xso,Yso,11,150+100,150-7-2,15) then
     begin
      Hide_Mouse;
       press_button(7+1,180+100,150-7-2,20,couleur_ppale,'Saisie ~Terme');
       delay(30);
       draw_button(7+1,180+100,150-7-2,20,couleur_ppale,'Saisie ~Terme');
       val(text_input(11,150+100,150-7-2,couleur_ppale,'Terme'),ind,err);
       Show_Mouse;
     end;
     If Clipsouris(Xso,Yso,7+1,200+100+2,150-7-2,20) then
     begin
      Hide_Mouse;
       press_button(7+1,200+100+2,150-7-2,20,couleur_ppale,'Calcul ~Suivi');
       if ind=0 then
       val(text_input(11,150+100,150-7-2,couleur_ppale,'Terme'),ind,err);
       Calcule_terme_c(ind);
       draw_button(7+1,200+100+2,150-7-2,20,couleur_ppale,'Calcul ~Suivi');
      Show_Mouse;
     end;
     If Clipsouris(Xso,Yso,7+1,220+100+4,150-7-2,20) then
     begin
      Hide_Mouse;
       press_button(7+1,220+100+4,150-7-2,20,couleur_ppale,'Calcul ~Final');
       if ind=0 then
       val(text_input(11,150+100,150-7-2,couleur_ppale,'Terme'),ind,err);
       Calcule_terme_f(ind);
       draw_button(7+1,220+100+4,150-7-2,20,couleur_ppale,'Calcul ~Final');
      Show_Mouse;
     end;
    { sortie }
     If Clipsouris(Xso,Yso,17,17,13,13) then
     begin
      Hide_Mouse;
      halt(0);
     end;
    { combo 1 }
     If Clipsouris(Xso,Yso,25-6, 56+100-6,12+80,12) then
       combox(1);
    { combo 2 }
     If Clipsouris(Xso,Yso,25-6, 76+100-6,12+80,12) then
       combox(2);
    { combo 3 }
     If Clipsouris(Xso,Yso,25-6, 96+100-6,12+80,12) then
       combox(3);
    { combo 4 }
     If Clipsouris(Xso,Yso,25-6,116+100-6,12+80,12) then
       combox(4);

   end;
   If keypressed then
             begin
                  c:=readkey;
                  if (c=#0) then     { code ‚tendu }
                    begin
                      c:=readkey;
                      case c of
                      #45:begin      { ALT-X }
                          Hide_Mouse;
                          halt(0);
                        end;
                      #20:begin      { ALT-T }
                          Hide_Mouse;
                          press_button(7+1,180+100,150-7-2,20,couleur_ppale,'Saisie ~Terme');
                          delay(30);
                          draw_button(7+1,180+100,150-7-2,20,couleur_ppale,'Saisie ~Terme');
                          val(text_input(11,150+100,150-7-2,couleur_ppale,'Terme'),ind,err);
                          Show_Mouse;
                        end;
                      #31:begin      { ALT-S }
                          Hide_Mouse;
                          press_button(7+1,200+100+2,150-7-2,20,couleur_ppale,'Calcul ~Suivi');
                          if ind=0 then
                          val(text_input(11,150+100,150-7-2,couleur_ppale,'Terme'),ind,err);
                          Calcule_terme_c(ind);
                          draw_button(7+1,200+100+2,150-7-2,20,couleur_ppale,'Calcul ~Suivi');
                          Show_Mouse;
                        end;
                      #33:begin      { ALT-F }
                          Hide_Mouse;
                          press_button(7+1,220+100+4,150-7-2,20,couleur_ppale,'Calcul ~Final');
                          delay(30);
                          if ind=0 then
                           val(text_input(11,150+100,150-7-2,couleur_ppale,'Terme'),ind,err);
                          Calcule_terme_f(ind);
                          draw_button(7+1,220+100+4,150-7-2,20,couleur_ppale,'Calcul ~Final');
                          Show_Mouse;
                        end;
                      #30:combox(1); { ALT-A }
                      #49:combox(2); { ALT-N }
                      #25:combox(3); { ALT-P }
                      #18:combox(4); { ALT-E }
                      #27:break;
                     end;
                    end;
             end;


 until Clipsouris(Xso,Yso,17,17,13,13);
end;

{ÍÍÍÍÍÍ[ Copyrights ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ25/05/95Í}
procedure copyrights;
var p:pointer;
begin
 Static_win(get_middle_screen_x-200,
            get_middle_screen_y-100-10,
            get_middle_screen_x+200,
            get_middle_screen_y+100+10,
            couleur_ppale,true);
 getviewsettings(wp);
 setviewport(get_middle_screen_x-200,
             get_middle_screen_y-100-10,
             get_middle_screen_x+200,
             get_middle_screen_y+100+10,
             false);
 draw_ico('esiea.ico',10,10);
 {rect_relief_inf(10,10,10+32,10+32,couleur_ppale);}
 draw_ico('wind.ico'  ,400-42,10);
 rect_relief_inf(400-42,10,
                 400-10,10+32,couleur_ppale);
{ loadbmp('\SCYTHALE.BMP',p);
 Showbmp(5,5,p);}

 settextstyle(triplexfont,horizdir,4);
 setcolor(white);
 outtextxy((400-textwidth('Remerciements')) div 2,10,'Remerciements');

 settextstyle(defaultfont,horizdir,1);
 ecrit_(10,60,'~Interface graphique : ',false);
 ecrit_((400-textwidth(ver_bgui))div 2,80,ver_bgui,false);

 ecrit_(10,100,'~Scrolling : ',false);
 ecrit_((400-textwidth('Squirrel 95'''))div 2,120,'Squirrel 95''',false);

 ecrit_(10,140,'~Routines math‚matiques : ',false);
 ecrit_((400-textwidth('Scythale 95'''))div 2,160,'Scythale 95''',false);

 ecrit_(10,180,'~Algorithme : ',false);
 ecrit_((400-textwidth('Matthieu Briand'))div 2,200,'Matthieu Briand',false);


 delay(2000);
 with wp do
   setviewport(x1,y1,x2,y2,clip);
 Statc;
end;

{ÍÍÍÍÍÍ[ GŠre l'‚cran ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ13/05/95Í}
begin

 Init_BGI;
 Init_Screen;
 Init_Mouse(Result);
 if not result then
   begin
     closegraph;
     writeln('Erreur, pas de souris');
     halt(255);
   end;

 pxi:=154+5+2;
 pyi:=43+5;
 pxm:=getmaxx-9-5;
 pym:=getmaxy-8-5;
 settextstyle(defaultfont,horizdir,1);
 settextjustify(lefttext,toptext);
 ty:=textheight('T');
 tx:=textwidth('W');
 px:=pxi;
 py:=pyi;

 Show_Mouse;
 Handle_Event;
 show_mouse;
 copyrights;
 dimdisplay(8);
 Closegraph;
end.
