--Autore: Luigi Treppiedi --Esercizio 4.3 --Calcolo del piu' piccolo divisore di N maggiore di 1 With Ada.Text_IO, Ada.Integer_Text_Io; Use Ada.Text_IO, Ada.Integer_Text_Io; Procedure piccolo_divisore_Treppiedi is Last :constant Integer:=1000; X,N :Integer:=1; Cont :Integer:=0; Num,i :Integer:=0; type Nprimi is array(1..Last) of Integer; Primo :Nprimi:=(others=>0); Begin Put("Ricerca del piu' piccolo divisore di N"); New_line; Put("Dammi un numero intero minore di 7500: "); Get(Num); If Num mod 2 = 0 then Put("Il piu' piccolo divisore e': 2"); Else Primo(1):=2; loop N:=N+1; X:=X+Cont; Cont:=0; loop if N mod Primo(X)=0 then exit; else if X-1=0 then X:=X+Cont+1; Cont:=0; Primo(X):=N; exit; else X:=X-1; Cont:=Cont+1; end if; end if; end loop; exit when Primo(X)>Num; end loop; Loop i:= i+1; Exit when num mod Primo(i)=0; End Loop; Put("Il piu' piccolo divisore e': "); Put(Primo(i)); End If; End piccolo_divisore_Treppiedi;