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<=I<=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