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