2015-year-school joint training first game Oo ' s Sequence (hdu5288)

Source: Internet
Author: User

Test instructions: Given a sequence of length n, which specifies that F (l,r) is for a l,r in the range of a number a[i], can not find a corresponding j to make a[i]%a[j]=0, then l,r within the number of i,f (L,R) is a few. Ask what the sum of all F (l,r) is.
The interval given in the formula is the interval of all existence.

Idea: Direct enumeration of each number, for this number, if the number is legal I, then the maximum length to the left can expand the maximum length is how much, then I is legal case is the left length * right length (including I and I is the number of valid interval).

Statistics left length can be judged a[i] of the approximate whether in the previous appeared ... Because a[i]<=10000, you can tag all the numbers on the left of I with an array a[k],k

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>using namespace STD;Const intMax =1e5+ -;Const intMoD =1e9+7;intA[max];intUsed[max];Long LongZuo[max];Long LongYou[max];intCalintx) {intm =sqrt(x*1.0);intMaxi = max (used[1],USED[X]); for(inti =2; I <= m; ++i) {if(x% i = =0{maxi = max (max (Maxi,used[i]), used[x/i]); }    }returnMaxi;}intMain () {intN while(~scanf("%d", &n)) {memset(Used,0,sizeof(used));memset(Zuo,0,sizeof(Zuo));memset(You,0,sizeof(you)); for(inti =1; I <= N; ++i) {scanf("%d", a+i);             Zuo[i] = i-cal (A[i]);        Used[a[i]] = i; }memset(Used,0,sizeof(used));//Turn to the right, n-i+1, you know the benefits of the simulation         for(inti =1; I <= N; ++i) {you[n-i+1] = i-cal (a[n-i+1]); used[a[n-i+1]] = i; }Long LongAns =0; for(inti =1; I <= N;        ++i) {ans + = (zuo[i]*you[i])%mod; }printf("%lld\n", Ans%mod); }return 0;}

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

2015-year-school joint training first game Oo ' s Sequence (hdu5288)

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.