Fermat's Last Theorem
Time limit1sMemory limit1024 MB
Count and sum the z^m values where z uses primes of |x+y| that divide neither x nor y, and z^m divides |x^n+y^n|, modulo 1e9+7.
- Level
Medium6 of 10
- Topics
- Math, Number theory
- Solved
- No attempts yet
Problem
Fermat's Last Theorem states the following.

Source: Facebook math gallery
Changho, who dreams of studying abroad, believes in Western learning, as the picture above shows. He boasts that he went beyond Fermat's Last Theorem and built his own, 'Changho's Last Theorem'. First, for an integer , call the set of distinct primes that appear in the prime factorization of the prime set of , written . Since cannot be factored into primes, . That is, if where the are distinct primes and each is an integer, then . Changho's Last Theorem is as follows.
For an odd nonnegative integer and nonzero integers and with , if there exists an integer such that , , and , then for every nonnegative integer , cannot be a multiple of .
Dongwoo found that this claim has many counterexamples. Given , , , and , count the that break the claim and sum them. That is, find the number and the sum of all that satisfy , , and , where is a multiple of .
Input
The first line contains an odd nonnegative integer (, ), nonzero integers and (, ), and an integer (), separated by spaces.
Output
For the given , , , and , print the number and the sum of all that satisfy , , , and for which is a multiple of , each taken modulo . Separate the two values with a space.