hdu 5228 OO’s Sequence 多校 思维题
2015-07-22 14:57
591 查看
点击打开链接
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1317 Accepted Submission(s): 467
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
Sample Output
Author
FZUACM
f(l,r)表示l<=i<=r,对任意l<=j<=r,j!=i,i%j!=0,i的个数
求所有f(l,r)之和
开两个数组l[i]和r[i]记录离a[i]最近的是a[i]因数或倍数的下标
由于a[i]小于10000
枚举是a[i]倍数的数就可以
代码:
OO’s Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1317 Accepted Submission(s): 467
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
Author
FZUACM
f(l,r)表示l<=i<=r,对任意l<=j<=r,j!=i,i%j!=0,i的个数
求所有f(l,r)之和
开两个数组l[i]和r[i]记录离a[i]最近的是a[i]因数或倍数的下标
由于a[i]小于10000
枚举是a[i]倍数的数就可以
代码:
#include<cstdio> #include<cstring> #include<algorithm> #include<vector> #define MAXN 111111 #define MOD 1000000007 using 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; }
相关文章推荐
- Exception in MessageQueue callback: handleReceiveCallback
- HDU5288 OO’s Sequence
- UIView - 常用方法总结
- ios开发UI篇—在ImageView中添加按钮以及Tag的参数说明
- 【多校第一场】【筛法改】HDU 5288 OO’s Sequence
- ios开发UI篇—Kvc简单介绍
- express4.x Request对象获得参数方法
- 关于是用UE的技巧--持续更新......
- Android build
- Bullet物理引擎不完全指南(Bullet Physics Engine not complete Guide)
- IOS自定义UITableViewCell的高亮背景色
- Storyboard中的UIScrollView使用自动布局,使其能够滚动
- ueditor 定制使用
- CALayer与UIView的关系
- Diesel-engined devices toronto and additionally equipment enjoy a great fanatic sticking with
- Errors occurred during the build. Errors running builder 'Checkstyle Builder' on project
- 2015 Multi-University Training Contest 1 - 1001 OO’s Sequence
- BlockingQueue(转自博客园)
- iOS 蓝牙使用小结 bluetooth
- 利用Loader来动态加载不同的QML文件来改变UI