fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int snt(int a){
  5. int x=0;
  6. for (int i=2; i*i<=a; i++){
  7. if (a%i==0) x++;
  8. }
  9. if (x==0) return 1;
  10. else return 0;
  11. }
  12.  
  13. int main() {
  14. int n, x=0;
  15. cin>>n;
  16. int ntt[n], a[n], b[n];
  17. for (int i=0; i<n; i++){
  18. cin>>ntt[i];
  19. b[i]=0;
  20. }
  21. for (int i=0; i<=n; i++){
  22. if (snt(ntt[i])==1){
  23. a[x]=ntt[i];
  24. b[x]=i;
  25. x++;
  26. }
  27. }
  28. sort (a, a+x-1);
  29. for (int x=0; x<n; x++){
  30. ntt[b[x]]=a[x];
  31. cout<<ntt[x]<<" ";
  32. }
  33. }
Success #stdin #stdout 0s 5380KB
stdin
10
10 9 8 7 6 5 4 3 2 1
stdout
10 9 8 1 6 2 4 3 5 7