codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

197B.md (2483B)


      1 Source: https://codeforces.com/problemset/problem/197/B
      2 
      3 B. Limit
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 You are given two polynomials:
     22 
     23 * *P*(*x*) = *a*0·*x**n* + *a*1·*x**n* - 1 + ... + *a**n* - 1·*x* + *a**n* and
     24 * *Q*(*x*) = *b*0·*x**m* + *b*1·*x**m* - 1 + ... + *b**m* - 1·*x* + *b**m*.
     25 
     26 Calculate limit ![](https://espresso.codeforces.com/151a1182fb7e3155744251b4e0170112e7c0aff9.png).
     27 
     28 Input
     29 
     30 The first line contains two space-separated integers *n* and *m* (0 ≤ *n*, *m* ≤ 100) — degrees of polynomials *P*(*x*) and *Q*(*x*) correspondingly.
     31 
     32 The second line contains *n* + 1 space-separated integers — the factors of polynomial *P*(*x*): *a*0, *a*1, ..., *a**n* - 1, *a**n* ( - 100 ≤ *a**i* ≤ 100, *a*0 ≠ 0).
     33 
     34 The third line contains *m* + 1 space-separated integers — the factors of polynomial *Q*(*x*): *b*0, *b*1, ..., *b**m* - 1, *b**m* ( - 100 ≤ *b**i* ≤ 100, *b*0 ≠ 0).
     35 
     36 Output
     37 
     38 If the limit equals  + ∞, print "Infinity" (without quotes). If the limit equals  - ∞, print "-Infinity" (without the quotes).
     39 
     40 If the value of the limit equals zero, print "0/1" (without the quotes).
     41 
     42 Otherwise, print an irreducible fraction — the value of limit ![](https://espresso.codeforces.com/151a1182fb7e3155744251b4e0170112e7c0aff9.png), in the format "p/q" (without the quotes), where *p* is the — numerator, *q* (*q* > 0) is the denominator of the fraction.
     43 
     44 Examples
     45 
     46 Input
     47 
     48 ```
     49 2 1  
     50 1 1 1  
     51 2 5
     52 ```
     53 
     54 Output
     55 
     56 ```
     57 Infinity
     58 ```
     59 
     60 Input
     61 
     62 ```
     63 1 0  
     64 -1 3  
     65 2
     66 ```
     67 
     68 Output
     69 
     70 ```
     71 -Infinity
     72 ```
     73 
     74 Input
     75 
     76 ```
     77 0 1  
     78 1  
     79 1 0
     80 ```
     81 
     82 Output
     83 
     84 ```
     85 0/1
     86 ```
     87 
     88 Input
     89 
     90 ```
     91 2 2  
     92 2 1 6  
     93 4 5 -7
     94 ```
     95 
     96 Output
     97 
     98 ```
     99 1/2
    100 ```
    101 
    102 Input
    103 
    104 ```
    105 1 1  
    106 9 0  
    107 -5 2
    108 ```
    109 
    110 Output
    111 
    112 ```
    113 -9/5
    114 ```
    115 
    116 Note
    117 
    118 Let's consider all samples:
    119 
    120 1. ![](https://espresso.codeforces.com/c28febca257452afdfcbd6984ba8623911f9bdbc.png)
    121 2. ![](https://espresso.codeforces.com/1e55ecd04e54a45e5e0092ec9a5c1ea03bb29255.png)
    122 3. ![](https://espresso.codeforces.com/2c95fb684d373fcc1a481cfabeda4d5c2f3673ee.png)
    123 4. ![](https://espresso.codeforces.com/4dc40cb8b3cd6375c42445366e50369649a2801a.png)
    124 5. ![](https://espresso.codeforces.com/c6455aba35cfb3c4397505121d1f77afcd17c98e.png)
    125 
    126 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