Under construction

Still being built. Things may change

Fermat's Last Theorem

Time limit1sMemory limit1024 MB

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

∄(x,y,z)∈(Z∖{0})3s.t.xn+yn=zn (n≥3,n∈Z,xyz≠0)\nexists (x, y, z) \in (\mathbb{Z}\setminus\{0\})^3 \quad \text{s.t.} \quad x^n + y^n = z^n \ (n \ge 3, n \in \mathbb{Z}, xyz \ne 0)

Joseon factional politics viewed through Fermat's Last Theorem

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 k≥2k \ge 2, call the set of distinct primes that appear in the prime factorization of kk the prime set of kk, written p(k)\mathbb{p}(k). Since 11 cannot be factored into primes, p(1)=∅\mathbb{p}(1) = \emptyset. That is, if k=p1e1p2e2⋯ptetk = p_1^{e_1} p_2^{e_2} \cdots p_t^{e_t} where the pip_i are distinct primes and each ei≥1e_i \ge 1 is an integer, then p(k)={p1,p2,⋯ ,pt}\mathbb{p}(k) = \{p_1, p_2, \cdots, p_t\}. Changho's Last Theorem is as follows.

For an odd nonnegative integer nn and nonzero integers xx and yy with x+y≠0x + y \ne 0, if there exists an integer z≥1z \ge 1 such that p(z)∩p(∣x∣)=∅\mathbb{p}(z) \cap \mathbb{p}(\lvert x\rvert) = \emptyset, p(z)∩p(∣y∣)=∅\mathbb{p}(z) \cap \mathbb{p}(\lvert y\rvert) = \emptyset, and p(z)⊆p(∣x+y∣)\mathbb{p}(z) \subseteq \mathbb{p}(\lvert x+y\rvert), then for every nonnegative integer mm, ∣xn+yn∣\lvert x^n + y^n\rvert cannot be a multiple of zmz^m.

Dongwoo found that this claim has many counterexamples. Given nn, xx, yy, and mm, count the zmz^m that break the claim and sum them. That is, find the number and the sum of all zmz^m that satisfy p(z)∩p(∣x∣)=∅\mathbb{p}(z) \cap \mathbb{p}(\lvert x\rvert) = \emptyset, p(z)∩p(∣y∣)=∅\mathbb{p}(z) \cap \mathbb{p}(\lvert y\rvert) = \emptyset, and p(z)⊆p(∣x+y∣)\mathbb{p}(z) \subseteq \mathbb{p}(\lvert x+y\rvert), where ∣xn+yn∣\lvert x^n + y^n\rvert is a multiple of zmz^m.

Input

The first line contains an odd nonnegative integer nn (1≤n≤10181 \le n \le 10^{18}, n≡1(mod2)n \equiv 1 \pmod{2}), nonzero integers xx and yy (1≤∣x∣,∣y∣≤10181 \le \lvert x\rvert, \lvert y\rvert \le 10^{18}, x+y≠0x + y \ne 0), and an integer mm (1≤m≤10181 \le m \le 10^{18}), separated by spaces.

Output

For the given nn, xx, yy, and mm, print the number and the sum of all zmz^m that satisfy p(z)∩p(∣x∣)=∅\mathbb{p}(z) \cap \mathbb{p}(\lvert x\rvert) = \emptyset, p(z)∩p(∣y∣)=∅\mathbb{p}(z) \cap \mathbb{p}(\lvert y\rvert) = \emptyset, p(z)⊆p(∣x+y∣)\mathbb{p}(z) \subseteq \mathbb{p}(\lvert x+y\rvert), and for which ∣xn+yn∣\lvert x^n + y^n\rvert is a multiple of zmz^m, each taken modulo 1 000 000 0071\,000\,000\,007. Separate the two values with a space.

Examples4

  1. Example 1

    Input
    1 5 7 1
    
    Expected output
    6 28
    
  2. Example 2

    Input
    3 125 -17 2
    
    Expected output
    6 455
    
  3. Example 3

    Input
    5 -527 -5627 3
    
    Expected output
    1 1
    
  4. Example 4

    Input
    3 597245143738042799 1 2
    
    Expected output
    1152 783300247