fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int n, m, table[21][21], erase_col = 0, prime_nrs = 0;
  5.  
  6. int prime(int n) {
  7. if(n < 2) {
  8. return 0;
  9. }
  10. for(int d = 2; d * d <= n; ++d) {
  11. if(n % d == 0) {
  12. return 0;
  13. }
  14. }
  15. return 1;
  16. }
  17.  
  18. int main() {
  19. cin >> n >> m;
  20. for (int i = 1; i <= n; ++i) {
  21. for (int j = 1; j <= m; ++j) {
  22. cin >> table[i][j];
  23. }
  24. }
  25. int j = 1;
  26. while (j <= m) {
  27. prime_nrs = 0;
  28. for (int i = 1; i <= n; ++i) {
  29. if (prime(table[i][j]) == 1) {
  30. ++prime_nrs;
  31. }
  32. }
  33. if (prime_nrs == n && n > 1) {
  34. int line;
  35. erase_col = 1;
  36. for (line = 1; line < n; ++line) {
  37. if (table[line][j] >= table[line + 1][j]) {
  38. erase_col = 0;
  39. }
  40. }
  41. if (erase_col == 1) {
  42. for (int col = j; col < m; ++col) {
  43. for (line = 1; line <= n; ++line) {
  44. table[line][col] = table[line][col + 1];
  45. }
  46. }
  47. --m;
  48. } else {
  49. ++j;
  50. }
  51. } else {
  52. ++j;
  53. }
  54. }
  55. if (m == 0) {
  56. n = 0;
  57. cout << n << ' ' << m << '\n';
  58. } else {
  59. cout << n << ' ' << m << '\n';
  60. }
  61. for (int i = 1; i <= n; ++i) {
  62. for (j = 1; j <= m; ++j) {
  63. cout << table[i][j] << ' ';
  64. }
  65. cout << '\n';
  66. }
  67. return 0;
  68. }
Success #stdin #stdout 0.01s 5500KB
stdin
2 2
2 3
101 7
stdout
0 0