CF1798C.Candy Store
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The store sells n types of candies with numbers from 1 to n . One candy of type i costs bi coins. In total, there are ai candies of type i in the store.
You need to pack all available candies in packs, each pack should contain only one type of candies. Formally, for each type of candy i you need to choose the integer di , denoting the number of type i candies in one pack, so that ai is divided without remainder by di .
Then the cost of one pack of candies of type i will be equal to bi⋅di . Let's denote this cost by ci , that is, ci=bi⋅di .
After packaging, packs will be placed on the shelf. Consider the cost of the packs placed on the shelf, in order c1,c2,…,cn . Price tags will be used to describe costs of the packs. One price tag can describe the cost of all packs from l to r inclusive if cl=cl+1=…=cr . Each of the packs from 1 to n must be described by at least one price tag. For example, if c1,…,cn=[4,4,2,4,4] , to describe all the packs, a 3 price tags will be enough, the first price tag describes the packs 1,2 , the second: 3 , the third: 4,5 .
You are given the integers a1,b1,a2,b2,…,an,bn . Your task is to choose integers di so that ai is divisible by di for all i , and the required number of price tags to describe the values of c1,c2,…,cn is the minimum possible.
For a better understanding of the statement, look at the illustration of the first test case of the first test:
Let's repeat the meaning of the notation used in the problem:
ai — the number of candies of type i available in the store.
bi — the cost of one candy of type i .
di — the number of candies of type i in one pack.
ci — the cost of one pack of candies of type i is expressed by the formula ci=bi⋅di .
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤100000 ). Description of the test cases follows.
The first line of each test case contains a single integer n ( 2≤n≤200000 ) — the number of types of candies.
Each of the next n lines of each test case contains two integers ai and bi ( 1≤ai≤109 , 1≤bi≤10000 ) — the number of candies and the cost of one candy of type i , respectively.
It is guaranteed that the sum of n over all test cases does not exceed 200000 .
输出格式
For each test case, output the minimum number of price tags required to describe the costs of all packs of candies in the store.
输入输出样例
输入#1
5 4 20 3 6 2 14 5 20 7 3 444 5 2002 10 2020 2 5 7 7 6 5 15 2 10 3 7 7 5 10 1 11 5 5 1 2 2 8 2 6 7 12 12 3 5 3 9 12 9 3 1000000000 10000
输出#1
2 1 3 2 5
说明/提示
In the first test case, you can choose d1=4 , d2=6 , d3=7 , d4=5 . Then the cost of packs will be equal to [12,12,35,35] . 2 price tags are enough to describe them, the first price tag for c1,c2 and the second price tag for c3,c4 . It can be shown that with any correct choice of di , at least 2 of the price tag will be needed to describe all the packs. Also note that this example is illustrated by a picture in the statement.
In the second test case, with d1=4 , d2=2 , d3=10 , the costs of all packs will be equal to 20 . Thus, 1 price tag is enough to describe all the packs. Note that ai is divisible by di for all i , which is necessary condition.
In the third test case, it is not difficult to understand that one price tag can be used to describe 2 nd, 3 rd and 4 th packs. And additionally a price tag for pack 1 and pack 5 . Total: 3 price tags.