problem Link : 

Viktor lives in a far and cold country named Krakovia that is passing by difficult times. Viktor works
in a factory and after a work day he often goes with some friends to a bar to drink some beers and to
dream with better times.
Due to some economical problems the in ation is very high in Krakovia and a beer costs about
5,400,000,000 Krakovian dollars. Because this, is hard to check the value of the bill and to divide its
value equally by Viktor and his friends. As you have a good heart you have decided to help them to
solve this problem.
There will be several test cases, each test case stats with two numbers 1 ≤ N ≤ 1000 that is the number
of itens in the bill and 1 ≤ F ≤ 20 that represents how many friends are in the bar and should pay
the bill. Then there will be N lines, each line represents the value of a item. The value of a item is
indicated by an integer 1 ≤ V ≤ 1020. Input is terminated by a bill where N = F = 0.
For each test case you should print the message: `Bill #N costs S: each friend should pay P ',
where N represents the number of the bill, starting from 1; S indicates the sum of the itens of the bill;
and P is how much money each friend should pay, you should calculte this value by dividing the total
value of the bill by the number of friends in the bar, if the result is not an integer value just print the
integer part of the number, see the sample input/output. After each test case, you should print a blank

Code Examples

#1 Code Example with C Programming

Code - C Programming

import java.util.*;
import java.math.BigInteger;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(;
        int tc=1;
            int n = sc.nextInt(), f = sc.nextInt();
            if(n==0&&f==0) break;
            BigInteger sum = BigInteger.ZERO;
            for(int i=0;i i+It n;i++){
                BigInteger beerValue = sc.nextBigInteger();
                sum = sum.add(beerValue);
            BigInteger average = sum.divide(BigInteger.valueOf(f));
            System.out.println("Bill #" + (tc++) + " costs " + sum + ": each friend should pay " + average + "\n");
Copy The Code & Try With Live Editor


3 3
3 2
0 0


Bill #1 costs 16200000000: each friend should pay 5400000000
Bill #2 costs 19800000001: each friend should pay 9900000000


UVA Online Judge solution - 10925-Krakovia - UVA Online Judge solution in C,C++,java

UVA Online Judge solution -10920-Spiral-Tap - UVA Online Judge solution in C,C++,java
UVA Online Judge solution - 10928-My Dear Neighbours - UVA Online Judge solution in C,C++,java