fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int prim(int n) {
  5. if (n <= 1) return 0;
  6. for (int i = 2; i * i <= n; i++) {
  7. if (n % i == 0) return 0;}
  8. return 1;
  9. }
  10.  
  11. int main() {
  12. int n , m, ok = 0, x;
  13. cin >> n >> m;
  14. for(int i = 1; i <= n; i++) {
  15. cin >> x;
  16. if(!prim(x)) {
  17. ok = 1;
  18. cout << x << ' ';
  19. }
  20. else ok = 0;
  21. for(int j = 2; j <= m; j++) {
  22. cin >> x;
  23. if(ok)
  24. cout << x << ' ';
  25. }
  26. if(ok) cout << '\n';
  27. }
  28. }
  29.  
Success #stdin #stdout 0.01s 5288KB
stdin
4 6
4 20 15 23 18 9 
17 15 13 18 12 1 
15 8 23 23 14 18 
3 18 8 23 12 15 
stdout
4 20 15 23 18 9 
15 8 23 23 14 18