多校I 1001

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=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 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
We have carefully selected several similar problems for you:   5299  5298  5297  5296  5295 
 

#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();
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值