首页 > 代码库 > 2014多校5(1003)hdu4913(线段树区间操作)

2014多校5(1003)hdu4913(线段树区间操作)

Least common multiple

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 451    Accepted Submission(s): 151


Problem Description
bobo has an integer set S={x1,x2,…,xn}, where xi=2ai * 3bi.

For each non-empty subsets of S, bobo added the LCM (least common multiple) of the subset up. Find the sum of LCM modulo (109+7).
 

Input
The input consists of several tests. For each tests:

The first line contains n (1≤n≤105). Each of the following n lines contain 2 integers ai,bi (0≤ai,bi≤109).
 

Output
For each tests:

A single integer, the value of the sum.
 

Sample Input
2 0 1 1 0 3 1 2 2 1 1 2
 

Sample Output
11 174

题意:RT

思路:最小公倍数只能是形如2^a * 3^b,而每次求一种最小公倍数 2^i * 3^j 的和只需要考虑小于等于i 和 j 的集合总数就好了,这个计数可以用线段树来完成,按a从小到大的顺

序将b插入线段树(注意b要先离散化),对于相同的a在插入b的时候也要按照b从小到大插入,这是为了保证后面比b大的数还是在a之前插入的,然后可以用两个数组分别维护

小于等于b的集合数 f[o] 和 小于b的集合数 ff[o],然后f[o]-ff[o]就是此时等于b的集合数了,累加就好了,这题也是把我恶心了好久,sad~~

<script src="https://code.csdn.net/snippets/458256.js" type="text/javascript"></script>

2014多校5(1003)hdu4913(线段树区间操作)