Hdu 5288 OO ' s Sequence (2015 multi-school first game 1th) enumeration factor

Source: Internet
Author: User

title Link:http://acm.hdu.edu.cn/showproblem.php?pid=5288

Test Instructions: in the closed interval [l,r] There is a number a[i],a[i] can not be divisible to remove the number of other than itself, F (l,r) in this interval a[i] The number of such numbers, and now give you n number, for all the interval F (l,r) and.

Ideas: for each number a[i] find the position of his left and right closest to his factor, L, R, and record, then for each number A[i] have his l,r, and for each a[i] the sum of the number of values in F (l,r) is (i-l+1) * ( r-i+1)

Code:

1#include <cstdio>2#include <cstdlib>3#include <cmath>4#include <cstring>5#include <iostream>6#include <queue>7#include <algorithm>8#include <vector>9 using namespacestd;Ten #defineLL __int64 One #defineINF 0x3f3f3f3f A Const intmaxn=100005; - #defineMoD 1000000007 - intL[MAXN]; the intR[MAXN]; - intA[MAXN]; - intVISL[MAXN]; - intVISR[MAXN]; + LL ans; - intMain () + { A     intn,i,j; at      while(~SCANF ("%d",&N)) -     { -memset (VISL,0,sizeof(VISL)); -memset (VISR,0,sizeof(VISR)); -          for(i=1; i<=n;i++) -         { inscanf"%d",&a[i]); -l[i]=1; tor[i]=N; +         } -          for(i=1; i<=n;i++) the         { *              for(j=a[i];j<=10000; j+=A[i]) $             {Panax Notoginseng                 if(visr[j]&&r[visr[j]]==N) -r[visr[j]]=i-1; the             } +visr[a[i]]=i; A         } the          for(i=n;i>0; i--) +         { -              for(j=a[i];j<=10000; j+=A[i]) $             { $                 if(visl[j]&&l[visl[j]]==1) -l[visl[j]]=i+1; -             } thevisl[a[i]]=i; -         }Wuyians=0; the          for(i=1; i<=n;i++) -         { Wu             //printf ("%d%d\n", L[i],r[i]); -ans+= (LL) (i+1-l[i]) * (r[i]-i+1); Aboutans%=MoD; $         } -printf"%i64d\n", ans%MoD); -     } -     return 0; A}
View Code

Hdu 5288 OO ' s Sequence (2015 multi-school first game 1th) enumeration factor

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.