Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1572 Accepted Submission(s): 567
地址: 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 a
i
mod a
j=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 a i(0<a i<=10000)
In each test case:
First line: an integer n(n<=10^5) indicating the size of array
Second line:contain n numbers a i(0<a i<=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 <iostream>
#include <cstdio>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define LL __int64
using namespace std;
int a[100010],l[100010],r[100010];
int mark[10010];
const int MOD=1e9+7;
int main()
{
int n;
int i,j;
while(~scanf("%d",&n))
{
for( i=1;i<=n;i++)scanf("%d",&a[i]);
memset(mark,0,sizeof(mark));
for(i=1;i<=n;i++)
{
for(j=1,l[i]=0;j*j<=a[i];j++)
{
if(a[i]%j==0)
{
if(mark[j]) l[i]=max(l[i],mark[j]);
if(mark[a[i]/j]) l[i]=max(l[i],mark[a[i]/j]);
}
}
mark[a[i]]=i;
}
memset(mark,0,sizeof(mark));
for(i=n;i>0;i--)
{
for(j=1,r[i]=n+1;j*j<=a[i];j++)
{
if(a[i]%j==0)
{
if(mark[j]) r[i]=min(r[i],mark[j]);
if(mark[a[i]/j]) r[i]=min(r[i],mark[a[i]/j]);
}
}
mark[a[i]]=i;
}
LL ans=0;
for(i=1;i<=n;i++)
{
//printf("%d %d %d\n",l[i],r[i],(i-l[i])*(r[i]-i));
ans=(ans+(i-l[i])*(r[i]-i))%MOD;
}
printf("%I64d\n",ans);
}
return 0;
}