Hdu 5228 OO ' s Sequence multi-school thinking problem

Source: Internet
Author: User

Click to open link

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


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
F (l,r) denotes l<=i<=r, the number of arbitrary l<=j<=r,j!=i,i%j!=0,i

The sum of all f (l,r)

Open two arrays l[i] and R[i] Records A[i] The nearest is a[i] factor or multiple subscript

Because A[i] is less than 10000

Enumeration is the number of a[i] multiples that can be

Code:

#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #define MAXN 111111# Define MOD 1000000007using namespace Std;int l[maxn],r[maxn],pre[maxn];int a[maxn];int main () {    int n;    while (scanf ("%d", &n)!=eof) {        memset (pre,0,sizeof (pre));        for (int i=1;i<=n;i++) {            l[i]=1;            R[i]=n;            scanf ("%d", &a[i]);            for (int j=a[i];j<=10000;j+=a[i])                if (pre[j]!=0&&r[pre[j]]==n)                    r[pre[j]]=i-1;                pre[a[i]]=i;        }        memset (pre,0,sizeof (pre));        for (int i=n;i>=1;i--) {for            (int j=a[i];j<=10000;j+=a[i])                if (pre[j]!=0&&l[pre[j]]==1)                    l[pre[j]]=i+1;                pre[a[i]]=i;        }        Long long ans=0;        for (int i=1;i<=n;i++)            ans= (ans+ (i-l[i]+1) * (r[i]-i+1))%mod;        printf ("%d\n", ans);    }    return 0;}


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

Hdu 5228 OO ' s Sequence multi-school thinking problem

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.