HDU 5288 OO’s Sequence(数学啊 多校2015)
来源:互联网 发布:sql触发器for 编辑:程序博客网 时间:2024/05/17 04:06
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288
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)
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
51 2 3 4 5
Sample Output
23
Author
FZUACM
Source
2015 Multi-University Training Contest 1
题意:
给出n个数,让找到所有的区间内不能整除其它数的数的个数之和 !
PS:
代码如下:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define maxn 100017#define LL __int64const int mod = 1e9+7;LL l[maxn], r[maxn];//存储左边因子,右边因子的位置LL a[maxn];int main(){ int n; LL pre[maxn], last[maxn]; while(~scanf("%d",&n)) { for(int i = 1; i <= n; i++) { scanf("%I64d",&a[i]); l[i] = 1; r[i] = n;//初始化最左边的因子和最右边的因子都是本身 } memset(pre,0,sizeof(pre)); memset(last,0,sizeof(last)); for(int i = 1; i <= n; i++) { for(int j = a[i]; j <= 10000; j+=a[i])//枚举a[i]的倍数 { if(pre[j]!=0 && r[pre[j]] == n)//如果j已经出现并且在右边最近的因子还没有找到 { r[pre[j]] = i-1; } } pre[a[i]] = i; } for(int i = n; i >= 1; i--) { for(int j = a[i]; j <= 10000; j+=a[i])//枚举a[i]的倍数 { if(last[j]!=0 && l[last[j]] == 1)//如果j已经出现并且在左边最近的因子还没有找到 { l[last[j]] = i+1; } } last[a[i]] = i; }// for(int i=1;i<=n;i++){// printf("%d %I64d %I64d %I64d\n",i,l[i],r[i],(i-l[i]+1)*(r[i]-i+1));// } LL ans = 0; for(int i = 1; i <= n; i++) { ans+=((LL)(i-l[i]+1)*(r[i]-i+1))%mod; ans%=mod; } printf("%I64d\n",ans); } return 0;}
1 0
- HDU 5288 OO’s Sequence(数学啊 多校2015)
- hdu 5288 - OO’s Sequence 数学
- HDU 5288 OO’s Sequence(数学)——2015 Multi-University Training Contest 1
- HDU 5288 OO‘s sequence (技巧)
- HDU 5288 OO’s Sequence(数论)
- hdu 5288OO’s Sequence
- hdu 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- HDU 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- HDU 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- HDU 5288 OO’s Sequence
- HDU 5288 OO’s Sequence
- 【模拟】zoj3844
- android中添加注释
- [POJ 2378] Tree Cutting
- OpenJudge - 2757 : 最长上升子序列
- 转换与继承
- HDU 5288 OO’s Sequence(数学啊 多校2015)
- 闭包小例子
- maven从svn上检出报错解决
- Windows下 maven3.0.4的安装步骤+maven配置本地仓库
- 转发器、集线器、网桥、交换机、路由器和网关简介
- 多校第一场 1010 hdu 5297 Y sequence(容斥+二分)
- Snail—UI学习之得到某组件的方法
- 关闭redis
- javascript基础(二)