Fermat Equation (Fermat)
Time limit0.5sMemory limit1024 MB
Given a prime p and exponent n, count triples (x,y,z) with entries in 0..p-1 such that x^n + y^n = z^n mod p.
- Level
Medium7 of 10
- Topics
- Number theory, Math, Combinatorics, Implementation
- Solved
- No attempts yet
Problem
Given a prime and a natural number , write a program that finds the number of triples of integers () satisfying
Here means that is divisible by .
Input
The first line of the input contains a prime (). The second line contains a natural number ().
Output
Print one line to standard output consisting of the single integer .
Hint
Note For the input data used in grading, the value of is less than .