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 Input51 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; }
相关文章推荐
- HDU 5288 OO’s Sequence
- Android Studio 运行时出现 finished with non-zero exit value 2
- iOS:切换视图的第三种方式:UITabBarController标签栏控制器
- Android异步更新UI的方式之使用Handler消息传递机制
- vector list deque 的异同
- Java String,StringBuilder和StringBuffer的区别 StringBuilder > StringBuffer> String
- js获取json中key,value
- UICollectionView的无缝排序
- ios的UIImageView显示图片防止图片变形
- quick 3.3加载Spine问题
- PHP中include和require的区别详解
- Distinct Subsequences
- 62 Unique Paths
- eos入门笔记(nui版本)(一)
- UIButton
- iOS开发中UITableView和UItableViewCell的几种形式
- 贪心水题。UVA 11636 Hello World,LA 3602 DNA Consensus String,UVA 10970 Big Chocolate,UVA 10340 All in All,UVA 11039 Building Designing
- Repeated DNA Sequences 解答
- The requested URL Not Found问题
- The requested URL Not Found问题