func_code_string: #include <bits/stdc++.h>   const int nMax = 200001;   struct Segment {     int left;     int right;     long long sum;     long long forced;     Segment* lChild;     Segment* rChild;   };   Segment* initTree(int left, int right, long long forced) {     Segment* segment = new Segment;     segment->left = left;     segment->right = right;     segment->forced = forced;     if (left == right) {       segment->lChild = nullptr;       segment->rChild = nullptr;       segment->sum = left;       segment->forced = left;     } else {       segment->lChild = initTree(left, (left + right) / 2, forced);       segment->rChild = initTree((left + right) / 2 + 1, right, forced);       segment->sum = ((segment->rChild == nullptr) ? 0 : segment->rChild->sum) +                      ((segment->lChild == nullptr) ? 0 : segment->lChild->sum);     }     return segment;   }   int customMax(int fd, int sd) { return (fd > sd) ? fd : sd; }   int getValue(Segment* root, int item, int value = -1) {     if (root->left == root->right) {       if (value == -1) value = root->forced;       return value;     }     if (value == -1)       if (root->forced != -1) value = root->forced;     if (item <= (root->left + root->right) / 2)       return getValue(root->lChild, item, value);     else       return getValue(root->rChild, item, value);   }   int safeForceCheck(Segment* root, int left, int right, int threshold) {     if (left > right) return -1;     if (left == right)       if (getValue(root, left) >= threshold)         return -1;       else         return left;     int result;     if (getValue(root, (left + right) / 2) >= threshold) {       result = safeForceCheck(root, left, (left + right) / 2 - 1, threshold);     } else {       result = safeForceCheck(root, (left + right) / 2 + 1, right, threshold);       if (result == -1) result = (left + right) / 2;     }     return result;   }   void forceToSegment(Segment* root, int left, int right, long long forced,                       long long was_forced = -1) {     if (left < 0) return;     if (right < left) return;     if ((left == root->left) && (right == root->right)) {       root->forced = forced;       root->sum = (right - left + 1) * forced;       return;     }     if (was_forced == -1) was_forced = root->forced;     if (was_forced != -1) {       if (was_forced >= forced) return;       root->lChild->forced = was_forced;       root->lChild->sum =           (root->lChild->right - root->lChild->left + 1) * was_forced;       root->rChild->forced = was_forced;       root->rChild->sum =           (root->rChild->right - root->rChild->left + 1) * was_forced;       root->forced = -1;     }     if (right <= (root->left + root->right) / 2) {       forceToSegment(root->lChild, left, right, forced, was_forced);     } else if (left > (root->left + root->right) / 2) {       forceToSegment(root->rChild, left, right, forced, was_forced);     } else {       forceToSegment(root->lChild, left, (root->left + root->right) / 2, forced,                      was_forced);       forceToSegment(root->rChild, (root->left + root->right) / 2 + 1, right,                      forced, was_forced);     }     root->sum = ((root->rChild == nullptr) ? 0 : root->rChild->sum) +                 ((root->lChild == nullptr) ? 0 : root->lChild->sum);   }   int main() {     long n;     Segment* root;     scanf( %ld , &n);     std::vector<int> a(n);     std::vector<int> used(nMax, -1);     int maxA = 0;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       used[a[i]] = i;       if (a[i] > maxA) maxA = a[i];     }     maxA++;     std::vector<long long> downCount(maxA, 0);     std::vector<int> rowTail(n, 0);     std::vector<std::vector<int> > affective(maxA);     downCount[maxA - 1] = ((long long)n * (n + 1)) / 2;     for (int i = 1; i < maxA; ++i)       for (int j = i; j < maxA; j += i)         if (used[j] != -1) affective[i].push_back(used[j]);     root = initTree(0, n - 1, -1);     for (int i = maxA - 2; i >= 1; i--) {       if (affective[i].size() <= 1) {         downCount[i] = downCount[i + 1];       } else {         std::sort(affective[i].begin(), affective[i].end());         forceToSegment(root, affective[i][1] + 1,                        safeForceCheck(root, affective[i][1] + 1, n - 1, n), n);         forceToSegment(root, affective[i][0] + 1,                        safeForceCheck(root, affective[i][0] + 1, affective[i][1],                                       affective[i][affective[i].size() - 1]),                        affective[i][affective[i].size() - 1]);         forceToSegment(root, 0,                        safeForceCheck(root, 0, affective[i][0],                                       affective[i][affective[i].size() - 2]),                        affective[i][affective[i].size() - 2]);         downCount[i] = ((long long)n * (n)) - root->sum;       }     }     long long result = 0LL;     for (int i = maxA - 2; i >= 1; i--) {       result += (downCount[i + 1] - downCount[i]) * i;     }     printf( %I64d , result);     return 0;   }   