The Formula Sicheol Loved
Time limit1sMemory limit1024 MB
Compute two nested-sum formulas involving gcd and lcm over all index pairs up to N, each reduced modulo a prime K, for N up to 10^6.
- Level
Hard8 of 10
- Topics
- Number theory, Math, Prefix sum, Combinatorics
- Solved
- No attempts yet
Problem
Q1. How do you put an elephant in a refrigerator?
A1. You make a graduate student do it.
Q2. How do you find the value of a formula?
A2. You make a graduate student do it.
Sicheol, the best graduate student in Yeonhui-dong, expanded formulas the way the Han River flows, and the way he finished them was like an ocean.
Sicheol, who stole the hearts of people all over the world with his brilliant formula expansions, eventually caught the eye of a professor who loved formulas.
The professor wanted to know the values of the two formulas, but it was not easy. So the professor asked Sicheol to find the values of the two formulas.
At first Sicheol began expanding the formulas reluctantly, but in the end he came to love the two formulas because of the professor.
However, Sicheol was too busy preparing his graduation thesis, so he dumped the rest on Minsu, a fellow graduate student. Minsu thought the values of the two formulas could be large, so he plans to tell the professor the remainders when the values are divided by .
Let us find the values of the two formulas together with Minsu.
Input
The input is given as follows.
Output
On the first line, print the value of the first formula.
On the second line, print the value of the second formula.
The values can be large, so print the remainders when they are divided by .
Constraints
- , is prime
- All numbers in the input are integers.
Hint
Minsu, who caught the professor's eye, went on to a doctoral program with him.