cpp omtimum solution : Count Leaves time limit per test4 seconds memory limit per…
- User
cpp omtimum solution : Count Leaves time limit per test4 seconds memory limit per test256 megabytes Let n and d be positive integers. We build the the divisor tree Tn,d as follows:
The root of the tree is a node marked with number n . This is the 0 -th layer of the tree. For each i from 0 to d−1 , for each vertex of the i -th layer, do the following. If the current vertex is marked with x , create its children and mark them with all possible distinct divisors† of x . These children will be in the (i+1) -st layer. The vertices on the d -th layer are the leaves of the tree. For example, T6,2 (the divisor tree for n=6 and d=2 ) looks like this:
Define f(n,d) as the number of leaves in Tn,d .
Given integers n , k , and d , please compute ∑i=1nf(ik,d) , modulo 109+7 .
† In this problem, we say that an integer y is a divisor of x if y≥1 and there exists an integer z such that x=y⋅z .
Input Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104 ). The description of the test cases follows.
The only line of each test case contains three integers n , k , and d (1≤n≤109 , 1≤k,d≤105 ).
It is guaranteed that the sum of n over all test cases does not exceed 109 .
Output For each test case, output ∑i=1nf(ik,d) , modulo 109+7 .
Example InputCopy 3 6 1 1 1 3 3 10 1 2 OutputCopy 14 1 53 Note In the first test case, n=6 , k=1 , and d=1 . Thus, we need to find the total number of leaves in the divisor trees T1,1 , T2,1 , T3,1 , T4,1 , T5,1 , T6,1 .
T1,1 has only one leaf, which is marked with 1 . T2,1 has two leaves, marked with 1 and 2 . T3,1 has two leaves, marked with 1 and 3 . T4,1 has three leaves, marked with 1 , 2 , and 4 . T5,1 has two leaves, marked with 1 and 5 . T6,1 has four leaves, marked with 1 , 2 , 3 , and 6 . The total number of leaves is 1+2+2+3+2+4=14 .
In the second test case, n=1 , k=3 , d=3 . Thus, we need to find the number of leaves in T1,3 , because 13=1 . This tree has only one leaf, so the answer is 1 .
- Assistant