Advertisement
AlexAvram

#1608

Jan 16th, 2023
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. //problema #1608
  2. #include <iostream>
  3. #include <fstream>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <utility>
  7. using namespace std;
  8. ifstream f("sortare_divizori.in");
  9. ofstream g("sortare_divizori.out");
  10. short nrdiv(int a)
  11. {
  12.     int d=1, rez=0;
  13.     for (d=1; d*d<a; ++d)
  14.         if (a%d==0)
  15.             rez+=2;
  16.     if (d*d==a)
  17.         ++rez;
  18.     return rez;
  19. }
  20. bool comp(pair<int, int>A, pair<int,int>B)
  21. {
  22.     if (A.second<B.second)
  23.         return true;
  24.     else if (A.second==B.second && A.first>B.first)
  25.         return true;
  26.     return false;
  27. }
  28. vector<pair<int,int>>v;
  29. int main()
  30. {
  31.     short n; int x;
  32.     f>>n;
  33.     v.resize(n+1);
  34.     int i;
  35.     for (i=1; i<=n; ++i)
  36.     {
  37.         f>>x;
  38.         v[i]=make_pair(x, nrdiv(x));
  39.     }
  40.     sort (v.begin(), v.end(), comp);
  41.     for (i=n; i>=1; --i)
  42.         g<<v[i].first<<" ";
  43.     return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement