fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int n, m, table[21][21], erase_col = 0, prime_nrs = 0, mc;
  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. mc = m;
  21. for (int i = 0; i < n; ++i) {
  22. for (int j = 0; j < m; ++j) {
  23. cin >> table[i][j];
  24. }
  25. }
  26. for (int j = 0; j < m; ++j) {
  27. prime_nrs = 0;
  28. for (int i = 0; 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 = 0; line < n - 1; ++line) {
  37. if (table[line][j] >= table[line + 1][j]) {
  38. erase_col = 0;
  39. }
  40. }
  41. if (erase_col == 1) {
  42. for (line = 0; line < n; ++line) {
  43. table[line][j] = -1;
  44. }
  45. --mc;
  46. }
  47. }
  48. }
  49. cout << n << ' ' << mc << '\n';
  50. for (int i = 0; i < n; ++i) {
  51. for (int j = 0; j < m; ++j) {
  52. if (table[i][j] != -1) {
  53. cout << table[i][j] << ' ';
  54. }
  55. }
  56. cout << '\n';
  57. }
  58. return 0;
  59. }
Success #stdin #stdout 0.01s 5476KB
stdin
3 1
2
5
7
stdout
3 0