Under construction

Still being built. Things may change

Sushi Dinner

Time limit1sMemory limit1024 MB

Summary
Count pairs of subsets X and Y of {2, ..., n} where every x in X is coprime to every y in Y, modulo p.
Level

Medium7 of 10

Topics
Number theory, Dynamic programming, Bit manipulation
Solved
No attempts yet

Problem

Compute the number of ways to choose two subsets X,Y⊆{2,3,…,n}X, Y \subseteq \{2, 3, \dots, n\} such that there is no pair x∈Xx \in X, y∈Yy \in Y where xx and yy are not relatively prime. The sets XX and YY may be empty. Output the number of ways modulo pp.

Input

The input contains the integer nn and the modulo pp, separated by a space.

Output

Output the number of ways to choose the subsets X,Y⊆{2,3,…,n}X, Y \subseteq \{2, 3, \dots, n\} that satisfy the condition above.

Constraints

  • 2≤n≤5002 \le n \le 500
  • 0<p≤1 000 000 0000 < p \le 1\,000\,000\,000

Examples3

  1. Example 1

    Input
    3 10000
    
    Expected output
    9
    
  2. Example 2

    Input
    4 10000
    
    Expected output
    21
    
  3. Example 3

    Input
    100 100000000
    
    Expected output
    3107203