您的位置:首页 > 产品设计 > UI/UE

HDU 5288 OO’s Sequence

2015-09-15 10:16 447 查看

OO’s Sequence

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2927 Accepted Submission(s): 1041Problem DescriptionOO 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).InputThere are multiple test cases. Please process till EOF.In each test case:First line: an integer n(n<=10^5) indicating the size of arraySecond line:contain n numbers ai(0<ai<=10000)OutputFor each tests: ouput a line contain a number ans.Sample Input5
1 2 3 4 5Sample Output23
/*
∑i=1-n ∑j=i-n f(i,j)
其实是在求对于任一个i满足与其他成员互质的区间个数
则就可以采用类似线性筛的方法,将i的左右端点给记录下来
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long LL;
const int mod=1000000007;
#define N 100005
int a
;
int Hasha[10005],Hashb[10005];
int positiona
,positionb
;
int main(){
int x;
int sum;
int i,j,k;
while(~scanf("%d",&x)){
sum=0;
memset(Hasha,0,sizeof(Hasha));
for(i=1;i<=10000;i++) Hashb[i]=x+1;
for(i=1;i<=x;i++) scanf("%d",&a[i]);
for(i=1;i<=x;i++){
positiona[i]=Hasha[a[i]];
for(j=a[i];j<10005;j+=a[i]) Hasha[j]=i;
}
for(i=x;i>=1;i--){
positionb[i]=Hashb[a[i]]-1;
for(j=a[i];j<10005;j+=a[i]) Hashb[j]=i;
}
for(i=1;i<=x;i++){
//printf("%lld %lld\n",positiona[i],positionb[i]);
sum=(sum+(i-positiona[i])*(positionb[i]+1-i))%mod;
}
printf("%d\n",sum);
}
return 0;
}


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: