Nowhere P

AtCoder
IDjsc2021_d
Time2000ms
Memory256MB
Difficulty
You are given a prime number $P$ not less than $2$, which you don't like. Let's call an array of integers $A_1, A_2, \dots, A_N$ **very good** if it satisfies the following condition: * there is no $i$ with $1 \le i \le N$ and $A_1 + A_2 + \dots + A_i \equiv 0 \bmod P$. Consider all $(P-1)^N$ arrays of length $N$ with elements from $1$ to $P-1$. How many of them are **very good**? As this number can be very big, output it modulo $(10^9 + 7)$. ## Constraints * $N$ and $P$ are integers. * $1 ≤ N ≤ 10^9$ * $2 ≤ P ≤ 10^9$ ## Input Input is given from Standard Input in the following format: $N$ $P$ [samples]
Samples
Input #1
3 3
Output #1
2

Two arrays, $(1, 1, 2)$ and $(2, 2, 1)$, satisfy the condition.
Input #2
3 2
Output #2
0
Input #3
45108 2571593
Output #3
224219544
API Response (JSON)
{
  "problem": {
    "name": "Nowhere P",
    "description": {
      "content": "You are given a prime number $P$ not less than $2$, which you don't like. Let's call an array of integers $A_1, A_2, \\dots, A_N$ **very good** if it satisfies the following condition: *   there is no",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "jsc2021_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a prime number $P$ not less than $2$, which you don't like.\nLet's call an array of integers $A_1, A_2, \\dots, A_N$ **very good** if it satisfies the following condition:\n\n*   there is no...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments