fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int mdiv(int n)
  7. {
  8. if (n%2 == 0) return 2;
  9. for(unsigned int i = 3; i*i <= n; i+=2)
  10. if (n%i == 0) return i;
  11. return n;
  12. }
  13.  
  14. int main()
  15. {
  16. int N[60];
  17. for(int i = 0; i < 60; ++i) N[i] = rand()%100+2;
  18. sort(N,N+60,[](int a, int b){ int m = mdiv(a), n = mdiv(b);
  19. return m < n ? true : m > n ? false : a < b; });
  20. for(int i = 0; i < 60; ++i) cout << N[i] << " ";
  21.  
  22. }
  23.  
Success #stdin #stdout 0s 4500KB
stdin
Standard input is empty
stdout
4  24  26  28  28  28  32  38  42  44  58  58  60  64  64  64  70  72  72  74  82  84  86  88  88  92  94  98  100  15  21  39  51  69  69  69  75  75  93  25  65  85  95  95  13  13  17  17  23  23  29  31  31  31  37  37  61  71  79  83