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 ai units of candy each time it receives a visitor, and will be visited bi times by members of the Brap Lesh Mafia.
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.
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 ai and bi (0 ≤ ai ≤ 109; 0 ≤ bi ≤ 109) of house i (for 1 ≤ i ≤ N).
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
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
Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Nov 07, 2014
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
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?