多校1 OO’s Sequence 1001

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 256    Accepted Submission(s): 94


Problem Description
OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) , that there's no j(l<=j<=r,j<>i) satisfy ai mod aj=0,now OO want to know
i=1nj=inf(i,j) mod 109+7.
 

 

Input
There are 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)
 

 

Output
For each tests: ouput a line contain a number ans.
 

 

Sample Input
5 1 2 3 4 5
 

 

Sample Output
23
 

 

Source
 

 

Recommend
We have carefully selected several similar problems for you:  5299 5298 5297 5296 5295 
哈哈!
 1 #include <math.h>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 using namespace std;
 6 
 7 const int mod=1e9+7;
 8 
 9 int main()
10 {
11     int n,i,j,k;
12     int str[100005],spfa[10005],l[100005],r[100005];
13     int s;
14     while(scanf("%d",&n)!=EOF)
15     {
16         for(i=1;i<=n;i++)
17             scanf("%d",&str[i]);
18         for(i=1;i<=10000;i++)
19             spfa[i]=0;
20         for(i=1;i<=n;i++)
21             l[i]=0,r[i]=n+1;
22         for(i=1;i<=n;i++)
23         {
24             for(j=1;j<=sqrt(str[i]);j++)
25             {
26                 if(str[i]%j==0)
27                 {
28                     if(spfa[j]>l[i])
29                         l[i]=spfa[j];
30                     if(spfa[str[i]/j]>l[i])
31                         l[i]=spfa[str[i]/j];
32                 }
33             }
34             spfa[str[i]]=i;
35         }
36         for(i=10000;i>=1;i--)
37             spfa[i]=n+1;
38         for(i=n;i>=1;i--)
39         {
40             for(j=1;j<=sqrt(str[i]);j++)
41             {
42                 if(str[i]%j==0)
43                 {
44                     if(spfa[j]<r[i])
45                         r[i]=spfa[j];
46                     if(spfa[str[i]/j]<r[i])
47                         r[i]=spfa[str[i]/j];
48                 }
49             }
50             spfa[str[i]]=i;
51         }
52         s=0;
53         for(i=1;i<=n;i++)
54         {
55             s=(s+(i-l[i])*(r[i]-i)%mod)%mod;
56         }
57         printf("%d\n",s);
58     }
59     return 0;
60 }
View Code

 

posted @ 2015-07-21 20:33  cyd2014  阅读(175)  评论(0编辑  收藏  举报