### PEG Test - Halloween 2014

## Problem B: Brap Lesh Mafia

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

There are `N` houses that the Brap Lesh Mafia will target on Halloween. The `i`-th house will give out `a _{i}` units of candy each time it receives a visitor, and will be visited

`b`times by members of the Brap Lesh Mafia.

_{i}There are `K` 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 Format

The first line of input will contain the integers: `N`, `K` (1 ≤ `N` ≤ 10000; 1 ≤ `K` ≤ 1000000009).

`N` lines of input will follow. The `i`-th of these lines will contain values `a _{i}` and

`b`(0 ≤

_{i}`a`≤ 10

_{i}^{9}; 0 ≤

`b`≤ 10

_{i}^{9}) of house

`i`(for 1 ≤

`i`≤

`N`).

### Output Format

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 71 candies total. Split amongst 12, there are 11 candies left over for Rex.

### Sample Input 2

1 1000000007 1000000000 1000000000

### Sample Output 2

49

All Submissions

Best Solutions

**Point Value:** 5

**Time Limit:** 2.00s

**Memory Limit:** 16M

**Added:** Nov 07, 2014

**Author:** frenzybenzy

**Languages Allowed:**

C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

## Comments (Search)

Cameronon Aug 31, 2017 - 7:20:55 pm UTC Algorithm for big numbers?I'm planning to 'make' an algorithm which multiplies large numbers in the way that people do it by hand, then storing it in a string or array of integers. Before I start however, I want to know if there is any standard algorithm designed for this.

Also, unsigned long long int is the largest integer value datatype, right?

kobortoron Sep 01, 2017 - 2:46:50 am UTC Re: Algorithm for big numbers?