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;
}

HDU 5288(OO’s Sequence-区间互质情况统计)的更多相关文章

  1. HDU 5288 OO’s Sequence [数学]

     HDU 5288 OO’s Sequence http://acm.hdu.edu.cn/showproblem.php?pid=5288 OO has got a array A of size ...

  2. HDU 5288 OO’s Sequence 水题

    OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...

  3. HDU 5288 OO‘s sequence (技巧)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...

  4. HDU 5288——OO’s Sequence——————【技巧题】

    OO’s Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

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

    OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  6. hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)

    OO's Sequence                                                          Time Limit: 4000/2000 MS (Jav ...

  7. hdu 5288 OO’s Sequence(2015多校第一场第1题)枚举因子

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288 题意:在闭区间[l,r]内有一个数a[i],a[i]不能整除 除去自身以外的其他的数,f(l,r ...

  8. hdu 5288 OO’s Sequence 枚举+二分

    Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...

  9. hdu 5288 OO’s Sequence(计数)

    Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...

随机推荐

  1. HTML基础(四)表格

    定义和用法 <table> 标签定义 HTML 表格. 简单的 HTML 表格由 table 元素以及一个或多个 tr.th 或 td 元素组成. tr 元素定义表格行,th 元素定义表头 ...

  2. C++变量和基本类型

    1. 如何选择类型的准则 当明确知晓数值不可能为负的时候,应该选择无符号类型. 使用int执行整数运算的时候,在实际应用中,short常常显得太小而long一般和int有一样的尺寸,如果数值超过了in ...

  3. pwnable.kr lotto之write up

    源代码 : #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcnt ...

  4. [BZOJ 3823]定情信物

    题面 定情信物 题解 这题主要考高中物理和数学. 首先定义 \(f[i][j]\) 表示 \(i\) 维超立方体中第 \(j\) 维元素的数量,根据实际意义,我们可以推出递推式: \(f[i][j]= ...

  5. linux赋权限

    给该文件夹赋权限命令 chmod u+x service-hcm-job.sh

  6. POJ 1486 Sorting Slides【二分图匹配】

    题目大意:有n张幻灯片和n个数字,幻灯片放置有重叠,每个数字隶属于一个幻灯片,现在问你能够确定多少数字一定属于某个幻灯片 思路:上次刷过二分图的必须点后这题思路就显然了 做一次二分匹配后将当前匹配的边 ...

  7. To_Date函数用法

    spl> select * from emp          where dates          between          to_date('2007-06-12 10:00:0 ...

  8. 【git】git分支的合并

    原文: http://gitbook.liuhui998.com/3_3.html http://gitbook.liuhui998.com/5_3.html 一.如何分支的合并 在git中,可以使用 ...

  9. x1 carbon 扩展屏 模糊

    x1 carbon 扩展屏 模糊,扩展屏是dell的屏,分辨率最大是1920*1080, x1最大是2560*1440. 不论是通过DP mini转VGA,还是HDMI,输出都是模糊,只有复制屏幕的时 ...

  10. RedisDesktopManager 踩坑之旅

    虚拟机上装了redis, 本地Windows的RedisDesktopManager  connect failed. 解决方法: 1.修改 redis.conf 文件 bind 127.0.0.1 ...