hdu5288 (2015 + school 1) OO ' s Sequence

Source: Internet
Author: User


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&LT;=I&LT;=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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.