Problem descriptionnumber theory is interesting, while this problem is boring.
Here is the problem. Given an integer sequence A1, A2 ,..., An, let s (I) = {J | 1 <= j <I, and AJ is a multiple of AI }. if S (I) is not empty, Let f (I) be the maximum integer in S (I); otherwise, f (I) = I. now we define B I as AF (I ). similarly, let T (I) = {J | I <j <= n, and AJ is a multiple of AI }. if T (I) is not empty, let G (I) be the minimum integer in T (I); otherwise, g (I) = I. now we define CI as AG (I ). the boring sum of this sequence is defined as B1 * C1 + B2 * C2 +... + BN * CN.
Given an integer sequence, your task is to calculate its boring sum.
Inputthe input contains multiple test cases.
Each case consists of two lines. The first line contains an integer N (1 <=n <= 100000). The second line contains N integers A1, A2 ,..., An (1 <= AI <= 100000 ).
The input is terminated by n = 0.
Outputoutput the answer in a line.
Sample Input
51 4 2 3 90
Sample output
136 question: Give you an array and let you generate two new arrays. A requires that each number be located before it. If you can find the nearest one, which is a multiple of it, then it will be the number. Otherwise it will be your own, C will be looking for it later, and the idea of output crossover and multiplication will be: scanning record factor Processing# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> using namespace STD; typedef _ int64 ll; const int maxn = 100005; int A [maxn], B [maxn], C [maxn], vis [maxn]; int N; int main () {While (scanf ("% d", & n) = 1) {If (n = 0) break; For (INT I = 1; I <= N; I ++) scanf ("% d", & A [I]); memset (VIS, 0, sizeof (VIS); For (INT I = 1; I <= N; I ++) {If (vis [A [I]) B [I] = A [vis [A [I]; elseb [I] = A [I]; for (Int J = 1; j <= (INT) SQRT (double) A [I] + 0.5); j ++) {if (a [I] % J = 0) {vis [J] = I; vis [A [I]/J] = I ;}} memset (VIS, 0, sizeof (VIS); For (INT I = N; I> = 1; I --) {If (vis [A [I]) c [I] = A [vis [A [I]; elsec [I] = A [I]; for (Int J = 1; j <= (INT) SQRT (double) A [I] + 0.5); j ++) {if (a [I] % J = 0) {vis [J] = I; vis [A [I]/J] = I ;}} ll sum = 0; For (INT I = 1; I <= N; I ++) {sum + = (LL) B [I] * C [I];} printf ("% i64d \ n", sum);} return 0 ;}