2015多校联赛 ——HDU5288(数学)
来源:互联网 发布:注册的淘宝号怎么注销 编辑:程序博客网 时间:2024/05/23 13:53
OO’s Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 449 Accepted Submission(s): 158
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 (10^9+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
Source
2015 Multi-University Training Contest 1
求在[a , b] 中有多少个i 满足找不到另一个数j 使,a[i] % a[j] = 0
用L[],R[]分别记录左右离起最近的因子,ans+=(R[i]-i+1)*(i-L[i]+1)/2 %MOD
//自己并没有想到怎么做 (╯▽╰)
#include<cstdio>#include<cstring>#include<iostream>using namespace std ;const int maxn = 100010 ;const int mod = 1e9+7 ;int a[maxn];long long last[maxn] ;long long pre[maxn] ;long long l[maxn] ;long long r[maxn] ;int main(){ //freopen("1001.txt" ,"r" ,stdin) ; int n; while(~scanf("%d",&n)) { memset(pre,0,sizeof(pre)); memset(last,0,sizeof(last)); for(int i = 1;i <= n;i++) { l[i] = 1; r[i] = n; scanf("%d",&a[i]); for(int j = a[i];j < 10001;j+=a[i]) { if(pre[j] && r[pre[j]] == n) r[pre[j]] = i-1; pre[a[i]] = i; } } for(int i = n;i >=1;i--) { for(int j = a[i];j < 10001;j+=a[i]) { if(last[j] && l[last[j]]==1) l[last[j]] = i+1; last[a[i]] = i; } } long long ans = 0; for(long long int i = 1;i <= n;i++) ans= (ans+(((i-l[i]+1)%mod)*((r[i] - i +1)%mod))%mod)%mod; printf("%I64d\n",ans); } return 0 ;}
0 0
- 2015多校联赛 ——HDU5288(数学)
- HDU 4611 (2013多校联赛1001 数学+模拟)
- HDU6069---Counting Divisors(2017多校联赛:数学)
- 2015 多校联赛 ——HDU5289(二分+ST)
- 2015 多校联赛 ——HDU5299(树删边)
- 2015 多校联赛 ——HDU5305(搜索)
- 2015 多校联赛 ——HDU5303(贪心)
- 2015 多校联赛 ——HDU5301(技巧)
- 2015 多校联赛 ——HDU5319(模拟)
- 2015 多校联赛 ——HDU5323(搜索)
- 2015 多校联赛 ——HDU5316(线段树)
- 2015 多校联赛 ——HDU5325(DFS)
- 2015 多校联赛 ——HDU5302(构造)
- 2015 多校联赛 ——HDU5335(Walk out)
- 2015 多校联赛 ——HDU5334(构造)
- 2015 多校联赛 ——HDU5344(水)
- 2015 多校联赛 ——HDU5349(水)
- 2015 多校联赛 ——HDU5350(huffman)
- Hduoj2855【矩阵数学】
- Redis复制与可扩展集群搭建
- 傅立叶外推算法的python实现和缺点
- 内存管理
- 2015年需要了解的前端框架和语言
- 2015多校联赛 ——HDU5288(数学)
- linux新建用户tab无法补全命令
- Android:文件下载和写入SD卡——文件下载大小和网络不一致(偏大或下载不完整)
- android studio 离线安装步骤
- 公众号第三方平台开发 - 教程五 代公众号发起网页授权源码
- 日版iphone去除运营商更新提示
- 时间函数(date/time/datetime/julianday/strftime) -- sqlite
- Android ListView CheckBox状态错乱解析
- HD2014 青年歌手大奖赛_评委会打分