hdu5288(2015多校1)OO’s Sequence

OO’s Sequence

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

Total Submission(s): 353    Accepted Submission(s): 117

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(l,r)求[l,r]区间内存在多少i(区间内没有i的约数)。公式中给出的区间,也就是所有存在的区间。

记录l[i],r[i],i的约数存在的位置,要求最接近i的。可以用数组记录下出现的最接近当前位置的数。得到l[i],r[i]后,那么i可以被计数的区间也就有了,左边界为l[i]到i,右边界为i到r[i],那么i一共会被记录(i-l[i])*(r[i]-i)次,累加所有的计数。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
#define LL __int64
const int MOD = 1e9+7 ;
int a[100010] , l[100010] , r[100010] ;
int Map[10010] ;
int main() {
    int i , j , n ;
    LL ans ;
    while( scanf("%d", &n) != EOF ) {
        for(i = 1 ; i <= n ; i++)
            scanf("%d", &a[i]) ;
        memset(Map,0,sizeof(Map)) ;
        for(i = 1 ; i <= n ; i++) {
            for(j = 1 , l[i] = 0 ; j*j <= a[i] ; j++) {
                if( a[i]%j ) continue ;
                if( Map[j] ) l[i] = max(l[i],Map[j]) ;
                if( Map[a[i]/j] ) l[i] = max(l[i],Map[a[i]/j]) ;
            }
            Map[a[i]] = i ;
        }
        memset(Map,0,sizeof(Map)) ;
        for(i = n ; i > 0 ; i--) {
            for(j = 1 , r[i] = n+1 ; j*j <= a[i] ; j++) {
                if( a[i]%j ) continue ;
                if( Map[j] ) r[i] = min(r[i],Map[j]) ;
                if( Map[a[i]/j] ) r[i] = min(r[i],Map[a[i]/j]) ;
            }
            Map[a[i]] = i ;
        }
        for(i = 1 , ans = 0 ; i <= n ; i++) {
            ans = (ans + (i-l[i])*(r[i]-i) ) % MOD ;
        }
        printf("%I64d\n", ans) ;
    }
    return 0 ;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-14 11:11:00

hdu5288(2015多校1)OO’s Sequence的相关文章

HDU 5288 OO&#39;s sequence (2015多校第一场 二分查找)

OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 955    Accepted Submission(s): 358 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the nu

Hdu 5288 OO’s Sequence 2015多小联赛A题

OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1751    Accepted Submission(s): 632 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the n

HDU 5288 OO’s Sequence(多校第一场1001)

OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 900    Accepted Submission(s): 339 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the nu

解题报告 之 HDU5288 OO&#39; s Sequence

解题报告 之 HDU5288 OO' s Sequence 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 imod a j=0,now OO want to know () Input There are multipl

hdu 5228 OO’s Sequence 多校 思维题

点击打开链接 OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1317    Accepted Submission(s): 467 Problem Description OO has got a array A of size n ,defined a function f(l,r) represen

hdu 5288||2015多校联合第一场1001题

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 ai mod aj=0,now OO want to know ∑i

hdu5353||2015多校联合第六场1001 贪心

http://acm.hdu.edu.cn/showproblem.php?pid=5353 Problem Description There are n soda sitting around a round table. soda are numbered from 1 to n and i-th soda is adjacent to (i+1)-th soda, 1-st soda is adjacent to n-th soda. Each soda has some candies

HDOJ 5288 OO’s Sequence 水

预处理出每个数字的左右两边可以整除它的最近的数的位置 OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1880    Accepted Submission(s): 672 Problem Description OO has got a array A of size n ,defined a func

HDU 5288 OO‘s sequence

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 985    Accepted Submission(s): 375 Problem Description OO has got a array