akashtadwai

Max Star

Oct 11th, 2019
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. int N;
  2.     cin >> N;
  3.     vector<int> arr(N), visited(1000005), vis1(1005), result(N);
  4.     for (int &i : arr)
  5.       cin >> i;
  6.     for (int i = 0; i < N; i++) {
  7.       int flag = 0;
  8.       int k = 1;
  9.       if (arr[i] >= 1000) {
  10.         while (k * arr[i] <= 1000000) {
  11.           flag += visited[k * arr[i]];
  12.           k++;
  13.           if (flag >= i)
  14.             break;
  15.         }
  16.         visited[arr[i]]++;
  17.       } else
  18.         flag = vis1[arr[i]];
  19.       for (int j = 1; j <= 1000; j++) {
  20.         if (arr[i] < j)
  21.           break;
  22.         if (arr[i] % j == 0)
  23.           vis1[j]++;
  24.       }
  25.       result[i] = flag;
  26.     }
  27.     cout << *max_element(result.begin(), result.end()) << endl;
  28.   }
Add Comment
Please, Sign In to add comment