OO’s Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 888 Accepted Submission(s): 335
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 <cstdio>
#include <string>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
#define maxn 100000 + 10
#define MOD 1000000007
int a[maxn], n;
int ans;
vector<int> m[maxn];
///思路: 某个数存在于多少个区间与多少个区间含有这个数是等价的
void solve()
{
ans = 0;
for(int i = 1; i <= n; i++)
{
int l = 0, r = n + 1;
int t = sqrt(a[i] + 0.5);
for(int j = 1; j <= t; j++)
{
if(a[i] % j == 0) ///因子
{
for(int k=0; k<m[j].size(); k++)
{
if(m[j][k] < i) l = max(m[j][k], l);
else if(m[j][k] > i) r = min(m[j][k], r);
}
int tmp = a[i] / j;
if(j != a[i] / j)
for(int k=0; k<m[tmp].size(); k++)
{
if(m[tmp][k] < i) l = max(m[tmp][k], l);
else if(m[tmp][k] > i) r = min(m[tmp][k], r);
}
}
}
ans = (ans + (i - l) * (r - i)) % MOD;
}
printf("%d\n", ans);
}
int main()
{
while(~scanf("%d", &n))
{
for(int i=1; i<maxn; i++) m[i].clear();
for(int i=1; i<=n; i++)
{
scanf("%d", &a[i]);
m[a[i]].push_back(i);
}
solve();
}
}