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=1n∑j=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

2015 Multi-University Training Contest 1

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 }

时间: 2024-08-02 16:52:15

OO’s Sequence 1001的相关文章

HDU 5288 OO’s Sequence(多校第一场1001)

OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 900    Accepted Submission(s): 339 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the nu

[HDOJ5288]OO&#39;s Sequence

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288 转换成求从1到n可以整除A[i]的区间的数量.找离最近的A[i]最近的可以整除A[i]的l和r,因为再往左或者右必然包含l和r假如[l,i]有x个数字,[i,r]有y个数字,那么A[i]的贡献即(x+1)*(y+1)求A[i]对ans的贡献综合即求离A[i]最近的可以被A[i]整除的数 1 #include <cstdio> 2 #include <cstdlib> 3 #inc

hdu 5288 OO’s Sequence 分解因子

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288 OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 588    Accepted Submission(s): 209 Problem Description OO has got a array A of

hdu5288(2015多校1)OO’s Sequence

OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 353    Accepted Submission(s): 117 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the nu

Hdu 5288 OO’s Sequence 2015多小联赛A题

OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1751    Accepted Submission(s): 632 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the n

HDU 5288 OO’s Sequence (暴力枚举因子)

题目链接:HDU 5288 OO's Sequence 题意:给出一个n,表示n个数的序列,函数f(l,r)定义,在l,r区间中存在多少个数,不能被其他数整除.求累加所有子区间的函数值 思路:从ai的小范围入手 1.a不能被b整除,即a的所有因子中不存在b,所以打表枚举所有的数的因子. 2.找到一个数(位置为i)满足条件时最左端l和最右端r,(i-l)*(r-i)就是对答案的贡献. AC代码: #include <stdio.h> #include <algorithm> #inc

HDOJ 5288 OO’s Sequence 水

预处理出每个数字的左右两边可以整除它的最近的数的位置 OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1880    Accepted Submission(s): 672 Problem Description OO has got a array A of size n ,defined a func

OO’s Sequence

OO’s Sequence 题目抽象:给你一个整数序列.  对于它的每个非空的子集区间,有多少个整数不能整除其它数.求每个非空子集区间的这些数的总和. 分析:用L[i],R[i]表示a[i]中最近的约数. 超时代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include

【HDOJ 5288】OO’s Sequence

[HDOJ 5288]OO's Sequence 枚举 题目给了个函数f(l,r) 求区间[l,r]有多少个数满足区间内任何一个数都不为他的约数 算出i [1,n] 每个位置的数的最大满足范围 即该位置的数对结果的贡献 两个函数 l[] r[] 存储每个位置的数贡献范围 譬如: 5 4 3 2 1 2 4 五个数的贡献范围分别为 (0,2) (0,4) (0,4) (3,6) (4,6) 计算区间范围 开一个数组pre[]存放遍历到此时每个数字在之前出现的位置 i(1->n) 每遍历一个数 更新