fork download
  1. program ideone;
  2.  
  3. uses Math;
  4.  
  5. Const smax = 99; kmax = 99;
  6. Type arr2d = array[0..smax, 0..kmax] of smallint; simple = array[0..smax] of smallint;
  7. Var data:arr2d; i, j, n, m, count:smallint;
  8.  
  9. procedure writeArr(arr:simple; count:smallint);
  10. Var i:smallint;
  11. begin
  12. for i:=0 to count-1 do write(arr[i], ' ');
  13. writeln();
  14. end;
  15.  
  16. function isMersenNum(num:smallint):boolean;
  17. Var t:smallint;
  18. begin
  19. t:=num+1;
  20. while (floor(t/2)=t/2) and ((t/2)>1) do begin
  21. t := floor(t/2);
  22. end;
  23. if t/2 = 1 then isMersenNum := True else isMersenNum:=False;
  24. end;
  25.  
  26. function processData(data:arr2d):simple;
  27. Var res:simple; i, j:smallint;
  28. begin
  29. count:=0;
  30. for i:=0 to n-1 do for j:=0 to m-1 do if isMersenNum(data[i][j]) = True then begin
  31. res[count]:=data[i][j];
  32. count:=count+1;
  33. end;
  34. processData:=res;
  35. end;
  36.  
  37. begin
  38. read(n, m);
  39. for i:=0 to n-1 do for j:=0 to m-1 do read(data[i][j]);
  40. writeArr(processData(data), count);
  41. end.
Success #stdin #stdout 0.01s 5284KB
stdin
3 3
3 7 2
9 1 15
31 12 63
stdout
3 7 1 15 31 63