This page is still under construction.

Parts of this page are still being built. What you see may change.

The Formula Sicheol Loved

Time limit1sMemory limit1024 MB

Summary
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.

∑n=1N∑i=1n∑j=1ngcd(i,j)×lcm(i,j)\displaystyle\sum_{n=1}^N \sum_{i=1}^n \sum_{j=1}^n \mathrm{gcd}\left(i,j\right)\times\mathrm{lcm}\left(i,j\right)

∑n=1N∑i=1n∑j=1ngcd(i,j)×∑n=1N∑i=1n∑j=1nlcm(i,j)\displaystyle\sum_{n=1}^N \sum_{i=1}^n \sum_{j=1}^n \mathrm{gcd}\left(i,j\right) \times \displaystyle\sum_{n=1}^N \sum_{i=1}^n \sum_{j=1}^n\mathrm{lcm}\left(i,j\right)

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 KK.

Let us find the values of the two formulas together with Minsu.

Input

The input is given as follows.

NN KK

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 KK.

Constraints

  • 1≤N≤1061 \leq N \leq 10^6
  • 106≤K≤109+710^6 \leq K \leq 10^9+7, KK 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.

Examples2

  1. Example 1

    Input
    1 1000000007
    
    Expected output
    1
    1
    
  2. Example 2

    Input
    3 1000000007
    
    Expected output
    46
    648