hdu 5288 OO’s Sequence
2015-10-10 14:45
363 查看
OO’s Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2988 Accepted Submission(s): 1062
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
求所有子区间内 不被该区间内其他数整除的数的个数
标记 计算出每一个数能作为f()函数的解能在的最大区间 就能知道每一个数成为解的次数
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int has[100100]; int l[100100],r[100100]; int a[100100]; const int Mod=1e9+7; void Factor(int n,int j) //找左边的第一个因子 { l[j]=max(has ,has[1]); for(int i=2;i*i<=n;i++) { if(n%i==0) { l[j]=max(l[j],has[i]); l[j]=max(l[j],has[n/i]); } } return ; } void factor(int n,int j) //找右边的第一个因子 { r[j]=min(has ,has[1]); for(int i=2;i*i<=n;i++) { if(n%i==0) r[j]=min(r[j],has[i]),r[j]=min(r[j],has[n/i]); } return ; } int main() { int n; while(~scanf("%d",&n)) { memset(l,0,sizeof(l)); memset(has,0,sizeof(has)); //找左边因子时 所有数初始位置为0 for(int i=1; i<=n; i++) { scanf("%d",&a[i]); Factor(a[i],i); has[a[i]]=i; } for(int i=0;i<=n;i++) r[i]=n+1; for(int i=0;i<=100000;i++) has[i]=n+1; //找右边因子时 所有数初位置为n+1 for(int i=n;i>0;i--) { factor(a[i],i); has[a[i]]=i; } int sum=0; for(int i=1;i<=n;i++) { sum=(sum+(i-l[i])*(r[i]-i)%Mod)%Mod; //计算每个数成为解的次数 } printf("%d\n",sum); } return 0; }
相关文章推荐
- CEGUI-----动画
- 【Java GUI】Java GUI基金会
- 怪异模式(Quirks Mode)对 HTML 页面的影响
- apue第三章文件I/O
- Invalid ADAPTORNAME specified. Type 'imaqhwinfo' for a list of available ADAPTORNAMEs. Image acquisi
- UIMenuController 和 UIMenuItem 的使用
- IOS 自定义 UISegmentedControl
- IOS控制UITextField输入字数
- MySQL 更新中国列:1366 Incorrect string value 问题解决了
- SPOJ - DQUERY 主席树求区间有多少个不同的数(模板)
- Prince的十个按钮--运用了java中的GUI
- 雅虎UI 取色器 【笨笨 20151005】
- request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath
- UVA-1152 4 Values whose Sum is 0 (二分)
- Android UI模板设计 TopBar 标题栏的设计
- android 雷达UI
- UIScrollview自动布局,UIScrollviewAutolayoutDemo
- easyui datebox 只选择月份控件
- UE简单配置
- [Request processing failed; nested exception is java.lang.NullPointerException] with root cause