program trabalho2 ; var i, numprimos : integer ; vetor_primos : array [1..200] of integer ; procedure GeraPrimos ; var i, j : integer ; eprimo : boolean ; begin numprimos := 1 ; vetor_primos[numprimos] := 2 ; for i := 3 to 999 do begin eprimo := true ; for j := 1 to numprimos do if (i mod vetor_primos[j]) = 0 then begin eprimo := false ; j := numprimos ; end; if eprimo = true then begin inc (numprimos) ; vetor_primos[numprimos] := i ; end ; end ; end ; function difquads(a : integer): boolean ; var condicao, x, y : integer ; begin difquads := false ; for x := -1000 to 1000 do begin for y := -1000 to 1000 do begin condicao := x*x - y*y ; if condicao = a then begin difquads := true ; x := 1000 ; y := 1000 ; end ; end ; end ; end ; function nsomacubos(a : integer): boolean ; var condicao, x, y : integer ; begin nsomacubos := true ; for x := -10 to 10 do begin for y := -10 to 10 do begin condicao := x*x*x + y*y*y ; if condicao = a then begin nsomacubos := false ; x := 10 ; y := 10 ; end ; end ; end ; end ; function somaquads(a : integer): boolean ; var x, y : integer ; begin somaquads := false ; for x := 0 to 31 do begin for y := 0 to 31 do if ((x * x) + (y * y)) = a then begin somaquads := true ; x := 31; y := 31; end; end; end; function quadcubo(a : integer): boolean ; var x : integer ; begin quadcubo := false ; for x := 0 to 10 do if ((x * x) = a) and ((x * x * x) = a) then begin quadcubo := true ; x := 10; end; end; function tresfatprim(a : integer): boolean ; var num, x, resto : integer ; begin resto := abs (a); num := 0; x := 1; repeat if resto mod (vetor_primos[x]) = 0 then begin resto := resto div vetor_primos[x]; inc(num); end else inc(x); until resto = 1; if num = 3 then tresfatprim := true else tresfatprim := false ; end; function prim(a, b : integer): boolean ; var x : integer ; eprimo : boolean ; begin prim := false ; x := 1; repeat if vetor_primos[x] = a then begin prim := true; eprimo := true; end else inc (x); until (vetor_primos[x] > a) or (a > vetor_primos[b]) or (eprimo = true); end; function somaquadcubo(a : integer): boolean ; var x, y : integer ; begin somaquadcubo := false ; for x := 0 to 31 do begin for y := 0 to 31 do if ((x * x * x) + (y * y)) = a then begin somaquadcubo := true ; x := 31; y := 31; end; end; end; function somatresquads(a : integer): boolean ; var x, y, z : integer ; begin somatresquads := false ; for x := 0 to 31 do begin for y := 0 to 31 do begin for z := 0 to 31 do if ((x * x) + (y * y) + (z * z)) = a then begin somatresquads := true ; x := 31; y := 31; z := 31; end; end; end; end; Begin GeraPrimos; writeln ('CONJUNTO 1'); writeln ('Numeros procurados:'); for i := -999 to -100 do begin if ((difquads(i)=true) and (nsomacubos(i)=false)) or ((difquads(i)=false) and (nsomacubos(i)=true)) then begin write (i, ' '); end; end; for i := 100 to 999 do begin if ((difquads(i)=true) and (nsomacubos(i)=false)) or ((difquads(i)=false) and (nsomacubos(i)=true)) then begin write (i, ' '); end; end; writeln; writeln; writeln ('CONJUNTO 2'); writeln ('Numeros procurados:'); for i := -999 to -100 do begin if ((somaquads(i)=true) and (quadcubo(i)=false)) or ((somaquads(i)=false) and (quadcubo(i)=true)) then begin write (i, ' '); end; end; for i := 100 to 999 do begin if ((somaquads(i)=true) and (quadcubo(i)=false)) or ((somaquads(i)=false) and (quadcubo(i)=true)) then begin write (i, ' '); end; end; writeln; writeln; writeln ('CONJUNTO 3'); writeln ('Numeros procurados:'); for i := 100 to 999 do begin if ((tresfatprim(i)=true) and (prim(i,numprimos)=false)) or ((tresfatprim(i)=false) and (prim(i,numprimos)=true)) then begin write (i, ' '); end; end; writeln; writeln; writeln ('CONJUNTO 4'); writeln ('Numeros procurados:'); for i := -999 to -100 do begin if ((somaquadcubo(i)=true) and (somatresquads(i)=false)) or ((somaquadcubo(i)=false) and (somatresquads(i)=true)) then begin write (i, ' '); end; end; for i := 100 to 999 do begin if ((somaquadcubo(i)=true) and (somatresquads(i)=false)) or ((somaquadcubo(i)=false) and (somatresquads(i)=true)) then begin write (i, ' '); end; end; writeln; readln; End.