HDU 5288 OO ' s Sequence (multi-school first game 1001)

Source: Internet
Author: User

OO ' s SequenceTime limit:4000/2000 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): Accepted submission (s): 339


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

Authorfzuacm
Source2015 multi-university Training Contest 1




#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < Stdlib.h> #include <math.h>using namespace std;int l[100100],r[100010];int n;int a[100010];int visit[100100];    void Updatalr () {memset (visit,0,sizeof (visit));        for (int i=1;i<=n;i++) {int maxx = 0;        int t = sqrt (a[i]);                for (int j=t;j>=1;j--) {if (a[i]%j = = 0) {maxx = max (Maxx,visit[j]);            Maxx = Max (maxx,visit[a[i]/j]);        }} L[i] = Maxx;    Visit[a[i]] = i;   } for (int i=0;i<100001;i++) {Visit[i] = n + 1;        } for (int i=n;i>=1;i--) {int minn = n+1;        int t = sqrt (a[i]);                for (int j=t;j>=1;j--) {if (a[i]%j = = 0) {minn = min (minn,visit[j]);            Minn = min (minn,visit[a[i]/j]);        }} R[i] = Minn;    Visit[a[i]] = i; }}int Main () {WHile (scanf ("%d", &n)!=eof) {__int64 sum = 0;        memset (visit,0,sizeof (visit));        for (int i=1;i<=n;i++) {scanf ("%d", &a[i]);        } updatalr ();            for (int i=1;i<=n;i++) {__int64 LL = (__int64) (I-l[i]);            __int64 RR = (__int64) (R[i]-i);        sum = (sum + (LL*RR))%1000000007;    } printf ("%i64d\n", sum); } return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 5288 OO ' s Sequence (multi-school first game 1001)

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.