OO's Sequence ZQUOJ 25690

来源:互联网 发布:航模设计软件 编辑:程序博客网 时间:2024/05/21 18:43

OO's Sequence

  • Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
  • Total Submission(s): 14 Accepted Submission(s): 5
Description

OO has got a array A of size n, defined a function f(lr) represent the number of i (l ≤ i ≤ r), that there's no j (l ≤ j ≤ rj ≠ i) satisfy ai mod aj = 0, now OO want to know

Input

There are multiple test cases. Please process till EOF.

In each test case:

First line: an integer n (n ≤ 105) indicating the size of array

Second line:contain n numbers ai (0 < ai ≤ 10000)

Output

For each tests: ouput a line contain a number answer.

Sample Input

5
1 2 3 4 5

Sample Output

23

Source
2015 Multi-University Training 1

解析:
题意,定义f(l,r)为 l~r 区间内无法找到因子的数的总个数。这题的题意可以理解为,在给定的一个大区间内,求有多少个小区间
其中的数在本区间中没有因子。这题需要一个区间方面的知识公式:  (i-l)*(r-i)  既下标为i的数在l~r这个区间内有多少个包含a[i]
的小区间。那么这题只要找到每个数的l和r就可以解决了。 


代码解析:这道题活用了桶排序,读入一个数的时候也把该数读入t数组。然后每个数枚举一下因子,如果因子的t数组空间不为0,那么就说明这个数是数组内的数。那么就标记yz[j]为i,既j是i的因子。这样枚举之后就可以确定每一个数分别是那些数的因子。然后用一个for来枚举j是谁的左因子,或是谁的右因子,并记录该数的r或l为j。这样就可以确定每一个数的左右因子,然后利用公式求解。

 
0 0
原创粉丝点击