## Brap Lesh Mafia

View as PDF

Points: 5
Time limit: 1.0s
Memory limit: 16M

Author:
Problem types
##### PEG Test - Halloween 2014

The Brap Lesh Mafia is an organization that collects candy from unsuspecting neighborhoods during Halloween.

There are houses that the Brap Lesh Mafia will target on Halloween. The -th house will give out units of candy each time it receives a visitor, and will be visited times by members of the Brap Lesh Mafia.

There are members in the Brap Lesh Mafia. At the end of the day, the total amount of candy is divided evenly amongst its members such that each member receives the same amount of candy as any other member, and each member receives as much candy as possible. The leftover candy is fed to their pet dog, Rex.

Determine the amount of candy Rex will receive.

#### Input Specification

The first line of input will contain the integers: , .
lines of input will follow. The -th of these lines will contain values and of house (for ).

#### Output Specification

Output a single integer, the number of units of candy that Rex will receive.

#### Sample Input 1

4 12
1 4
2 9
3 8
5 5

#### Sample Output 1

11

#### Explanation 1

Brap Lesh Mafia collects candies total. Split amongst , there are candies left over for Rex.

#### Sample Input 2

1 1000000007
1000000000 1000000000

#### Sample Output 2

49

• commented on Jan. 9, 2022, 8:17 p.m. edited

I love Rex