OO’s Sequence

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 2643    Accepted Submission(s): 925

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=1nj=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
 
Source
 
Recommend
 
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
#include<vector>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (1000000007)
#define MAXN (1000000+10)
#define MAXn (1000000+10)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int a[MAXn],n;
ll l[MAXN],r[MAXN];
ll al[MAXN],ar[MAXN];
int main()
{
// freopen("A.in","r",stdin);
// freopen(".out","w",stdout); while(scanf("%d",&n)==1)
{
ll ans=0;
For(i,n) scanf("%d",&a[i]);
MEM(l) MEMI(r)
For(i,n)
{
al[i]=0;
int p=a[i];
for(int j=1;(ll)j*j<=(ll)p;j++) {
if (p%j==0) al[i]=max(al[i],max(l[j],l[p/j]));
}
l[a[i]]=i;
} ForD(i,n)
{
ar[i]=n+1;
int p=a[i];
for(int j=1;(ll)j*j<=(ll)p;j++) {
if (p%j==0) ar[i]=min(ar[i],min(r[j],r[p/j]));
}
r[a[i]]=i;
} // For(i,n) cout<<al[i]<<' ';cout<<endl;
// For(i,n) cout<<ar[i]<<' ';cout<<endl;
// For(i,n)
upd(ans,mul(i-al[i],ar[i]-i));
cout<<ans<<endl;
} return 0;
}

最新文章

  1. Android笔记
  2. 如何把Json格式字符写进text文件中
  3. JSP Workshop
  4. STL List容器
  5. 携程SQL面试题忘大牛解答解决思路
  6. C++学习笔记10-面向对象
  7. Java方法的概念及使用
  8. 【转载】asp.net core 2.0的认证和授权
  9. tomcat设置开机启动
  10. It is not safe to rely on the system&#39;s timezone settings错误
  11. for...in和for...of循环的区别
  12. MongoDB-增删改
  13. oracle 11g 分区表创建(自动按年、月、日分区)
  14. jsp泛型支持
  15. Java内存模型(一)
  16. python opencv3 直线检测
  17. delphi 获取本机IP地址和MAC地址
  18. bzoj1093[ZJOI2007]最大半连通子图(tarjan+拓扑排序+dp)
  19. 开启mysql日志及若干问题
  20. unity5.6里Baked Lighting下面几个Lighting Mode的解释

热门文章

  1. Unexpected Exception caught setting &#39;username&#39; on &#39;class com.bj186.crm.web.action.UserAction: Error setting expression &#39;username&#39; with value [&#39;艾格尼丝&#39;, ]
  2. eclipse修改SVN账号密码
  3. python 装饰器(二): 加参数
  4. POJ 1985 Cow Marathon (求树的直径)
  5. 关于shell中常见功能的实现方式总结
  6. AI学习笔记(01)
  7. spring boot学习02【如何在spring boot项目中访问jsp】
  8. Python 单向队列Queue模块详解
  9. php 面向对象 (类 对象)
  10. HDU1757-A Simple Math Problem,矩阵快速幂,构造矩阵水过