OO ' s SequenceTime
limit:4000/2000 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): 353 Accepted Submission (s): 117
Problem Descriptionoo has got a array a of size n, defined a function f (l,r) represent the number of I (L<=I<=R), t Hat there ' s no J (l<=j<=r,j<>i) satisfy AI mod aj=0,now OO want to know ∑ i = 1 n ∑j=in F (I,J) mod ( ten 9 +7).
Inputthere is multiple test cases. Please process till EOF.
In each test case:
First Line:an integer n (n<=10^5) indicating the size of array
Second line:contain N numbers ai (0<ai<=10000)
Outputfor each tests:ouput a line contain a number ans.
Sample Input
51 2 3) 4 5
Sample Output
23
F (l,r) The number of I within the [l,r] interval (no approximate of I in the interval). The interval given in the formula is the interval of all existence.
Records the position of the approximate existence of the l[i],r[i],i, requiring the closest to I. The number that appears closest to the current position can be recorded with an array. After getting l[i],r[i], then I can count the interval also has, the left bound for L[i] to I, the right bound for I to r[i], then I will be recorded (I-l[i]) * (r[i]-i) times, accumulate all counts.
#include <cstdio> #include <cstring> #include <algorithm>using namespace std; #define LL __int64const int MOD = 1e9+7; int a[100010], l[100010], r[100010]; int map[10010]; int main () {int I, j, N; LL ans; while (scanf ("%d", &n)! = EOF) {for (i = 1; I <= n; i++) scanf ("%d", &a[i]); memset (map,0,sizeof (MAP)); for (i = 1; I <= n; i++) {for (j = 1, l[i] = 0; j*j <= A[i]; j + +) {if (a[i]%j) Conti Nue; if (Map[j]) l[i] = max (l[i],map[j]); if (map[a[i]/j]) l[i] = max (l[i],map[a[i]/j]); } Map[a[i]] = i; } memset (Map,0,sizeof (MAP)); for (i = n; i > 0; i--) {for (j = 1, r[i] = n+1; j*j <= A[i]; j + +) {if (A[I]%J) cont Inue; if (Map[j]) r[i] = min (r[i],map[j]); if (map[a[i]/j]) r[i] = min (r[i],map[a[i]/j]); } MAP[A[i]] = i; } for (i = 1, ans = 0; I <= N; i++) {ans = (ans + (i-l[i) * (r[i]-i))% MOD; } printf ("%i64d\n", ans); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
hdu5288 (2015 + school 1) OO ' s Sequence