% Pimszam iteracio II - Faktorizacio all_primes = iter () yields ( int ) own prime_table : array[int] := array[int]$[2] i,p : int for pe : int in prime_table!elements do yield (pe) end %for p := prime_table!top + 1 while true do i := 1 while i <= prime_table!high cand p // prime_table[i] ~= 0 do i := i + 1 end %while if i > prime_table!high then prime_table!addh(p) yield (p) end %if p := p + 1 end %while end all_primes start_up = proc () pi: stream := stream$primary_input() po: stream := stream$primary_output() s, pre : string n : int po!putl("Primszam iteracio Demo II - Factorizacio") while true do po!putl("Adjon meg egy szamot (RETURN kilepes): ") s := pi!getl if s!empty then break end n := int$parse(s) except when bad_format, overflow: po!putl("Hibas szam!") continue end if n < 2 then po!putl("Rossz ertek! (< 2)") continue end %if pre := " = " for d : int in all_primes() do k : int := 0 while n // d = 0 do k := k + 1 n := n / d end %while if k > 0 then po!putl(pre || d!unparse || " ^ " || k!unparse) if n < 2 then break end if pre = " = " then pre := " * " end %if end %if end %for end %while end start_up