Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int N;
- cin >> N;
- vector<int> arr(N), visited(1000005), vis1(1005), result(N);
- for (int &i : arr)
- cin >> i;
- for (int i = 0; i < N; i++) {
- int flag = 0;
- int k = 1;
- if (arr[i] >= 1000) {
- while (k * arr[i] <= 1000000) {
- flag += visited[k * arr[i]];
- k++;
- if (flag >= i)
- break;
- }
- visited[arr[i]]++;
- } else
- flag = vis1[arr[i]];
- for (int j = 1; j <= 1000; j++) {
- if (arr[i] < j)
- break;
- if (arr[i] % j == 0)
- vis1[j]++;
- }
- result[i] = flag;
- }
- cout << *max_element(result.begin(), result.end()) << endl;
- }
Add Comment
Please, Sign In to add comment