Problem Link: http://www.spoj.com/problems/JULKA/
The problem is about “Klaudia and Natalia have 10 apples together, but Klaudia has two apples more than Natalia. How many apples does each of he girls have?“. Input contains n which represents total number of apples and k difference between klaudia and natalia apples. The solution I submitted is to divide the n by 2(based on even or add) and store in two variable try to remove one from one of the variable till k(based on n even or odd).

As the solution is simple, this problem mainly concentrates how to handle large inputs. As I am solving in java, it is an exercise on how to use java.math.BigInteger.

Solution Link: https://github.com/bharaththiruveedula/Algorithms/blob/master/SPOJ/JULKA.java

Advertisements