Birthday Party
Time limit5sMemory limit512 MB
Count ordered tuples of f positive integers summing to n whose greatest common divisor is 1, modulo 1e9+7, for up to 100000 queries.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Number theory, Combinatorics, Math
- Solved
- No attempts yet
Problem
Today is Sanggeun's birthday. He invited friends to the party and has candies to hand out. The friends are numbered from to .
Sanggeun hands out the candies under these two rules.
- Every friend receives at least one candy.
- Let be the number of candies friend receives. There must be no positive integer that divides every .
Given and , write a program that counts the ways to hand out the candies.
Two ways are different when some friend receives a different number of candies. For example, giving 1 candy to friend 1 and 2 candies to friend 2 differs from giving 2 candies to friend 1 and 1 candy to friend 2.
Input
The first line contains the number of test cases ().
Each of the next lines contains and , separated by a space. ()
Output
For each test case, print the number of ways to hand out the candies modulo , one per line.
Hint
For and , the possible ways are and .
For and , the possible ways are , , , , , .