Advertisement
tungSfer

Untitled

Jan 13th, 2022
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll long long
  4. #define el endl
  5.  
  6. const int mod = 1e9 + 7;
  7.  
  8. using namespace std;
  9.  
  10. void solve()
  11. {
  12.     int n;
  13.     cin >> n;
  14.     int a[n];
  15.     int sum1 = 0;
  16.     for(int i = 0; i < n; i++)
  17.     {
  18.         cin >> a[i];
  19.         sum1 += a[i];
  20.     }
  21.     sort(a, a + n);
  22.     int b[n];
  23.     int base = a[0];
  24.     while(base > 0)
  25.     {
  26.         bool ok = true;
  27.         b[0] = a[0] / base;
  28.         for(int i = 1; i < n; i++)
  29.         {
  30.             b[i] = a[i] / base;
  31.         }
  32.         for(int i = 0; i < n; i++)
  33.         {
  34.             if(base != a[i] / b[i])
  35.             {
  36.                 ok = false;
  37.                 break;
  38.             }
  39.         }
  40.         if(ok)
  41.         {
  42.             break;
  43.         }
  44.         base--;
  45.     }
  46.     for(int i = 0; i < n; i++)
  47.         while( b[i] - 1 > 0 && a[i] / (b[i] - 1) == base)
  48.         {
  49.             b[i]--;
  50.         }
  51.     int res = 0;
  52.     if(base)
  53.     {
  54.         for(int i = 0; i < n; i++)
  55.         {  
  56. //      cout<<b[i]<<" ";
  57.             res += b[i];
  58.         }
  59.         cout << res;
  60.     }
  61.    
  62. }
  63.  
  64. int main()
  65. {
  66.     solve();
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement