CF BUDDY
← Problems·

197B · Limit

1400 · math

Problem: You are given two polynomials:

  • P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and
  • Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm.

Calculate limit limx+P(x)Q(x)\lim_{x \to +\infty} \frac{P(x)}{Q(x)}.

Input Format: The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly.

The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0).

The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).

Output Format: If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes).

If the value of the limit equals zero, print "0/1" (without the quotes).

Otherwise, print an irreducible fraction — the value of limit limx+P(x)Q(x)\lim_{x \to +\infty} \frac{P(x)}{Q(x)}, in the format "p/q" (without the quotes), where p is the — numerator, q (q > 0) is the denominator of the fraction.

Note: Let's consider all samples:

  1. limx+x2+x+12x+5=+\lim_{x \to +\infty} \frac{x^2+x+1}{2x+5} = +\infty
  2. limx+x+32=\lim_{x \to +\infty} \frac{-x+3}{2} = -\infty
  3. limx+1x=0\lim_{x \to +\infty} \frac{1}{x} = 0
  4. limx+2x2+x+64x2+5x7=12\lim_{x \to +\infty} \frac{2x^2+x+6}{4x^2+5x-7} = \frac{1}{2}
  5. limx+9x5x+2=95\lim_{x \to +\infty} \frac{9x}{-5x+2} = -\frac{9}{5}

You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function

Sample Cases

Case 1

Input

2 1
1 1 1
2 5

Output

Infinity

Case 2

Input

1 0
-1 3
2

Output

-Infinity

Case 3

Input

0 1
1
1 0

Output

0/1

Case 4

Input

2 2
2 1 6
4 5 -7

Output

1/2

Case 5

Input

1 1
9 0
-5 2

Output

-9/5

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback