codeforces-scrape

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

495B.md (2028B)


      1 Source: https://codeforces.com/problemset/problem/495/B
      2 
      3 B. Modular Equations
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by ![](https://espresso.codeforces.com/dd2b46f89067e3a9d9987c4263de702dd7518fa7.png). A Modular Equation, as Hamed's teacher described, is an equation of the form ![](https://espresso.codeforces.com/fc4bae676fb9b7279f0b9e6781d3d2d6abf86586.png) in which *a* and *b* are two non-negative integers and *x* is a variable. We call a positive integer *x* for which ![](https://espresso.codeforces.com/fc4bae676fb9b7279f0b9e6781d3d2d6abf86586.png) a solution of our equation.
     22 
     23 Hamed didn't pay much attention to the class since he was watching a movie. He only managed to understand the definitions of these equations.
     24 
     25 Now he wants to write his math exercises but since he has no idea how to do that, he asked you for help. He has told you all he knows about Modular Equations and asked you to write a program which given two numbers *a* and *b* determines how many answers the Modular Equation ![](https://espresso.codeforces.com/fc4bae676fb9b7279f0b9e6781d3d2d6abf86586.png) has.
     26 
     27 Input
     28 
     29 In the only line of the input two space-separated integers *a* and *b* (0 ≤ *a*, *b* ≤ 109) are given.
     30 
     31 Output
     32 
     33 If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation ![](https://espresso.codeforces.com/fc4bae676fb9b7279f0b9e6781d3d2d6abf86586.png).
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 21 5
     41 ```
     42 
     43 Output
     44 
     45 ```
     46 2
     47 ```
     48 
     49 Input
     50 
     51 ```
     52 9435152 272
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 282
     59 ```
     60 
     61 Input
     62 
     63 ```
     64 10 10
     65 ```
     66 
     67 Output
     68 
     69 ```
     70 infinity
     71 ```
     72 
     73 Note
     74 
     75 In the first sample the answers of the Modular Equation are 8 and 16 since ![](https://espresso.codeforces.com/6f5ff39ebd209bf990adaf91f4b82f9687097224.png)