EXOCODE5 - Editorial

Problem Link-https://www.codechef.com/problems/EXOCODE5



PREREQUISITES-Big-Integer,Basic Java Programming

PROBLEM:Chef is a brave Warrior who with his group of young soldiers moves from one place to another to fight against his opponents. Before Fighting he just calculates two things,the difference between his soldier number and the type of opponent’s soldier number.

From this difference and the opponent army soldier number type (even or odd number)?, he decides whether to fight or not?

Print the difference and the type of opponent army soldier number!

Chef ‘s opponent number is never greater than Chef number.

Constraints:The numbers are less than 10^25

EXPLANATION:From the Question statement it is crystal clear that we have to find difference between chef army soldier number and opponent soldier number.
Numbers are large so we have to use Big-Integer Class(The java.math.BigInteger class provides operations analogues to all of Java’s primitive integer operators and for all relevant methods from java.lang.Math.)

Introduction to Big Integer-https://goo.gl/WZis9f

IN C/C++ -http://codeforces.com/blog/entry/16380

Using BigInteger class function subtract we calculated the difference,then we have to check whether opponent soldier number is even or odd.
(A number is said to be even number if it leaves no remainder when divided by 2. There is an alternative definition of even number and it is as a number having any number from 0, 2, 4, 6 and 8 at its ones place is an even number. Examples of even numbers are 12, 66, 456, 9900 and 12342 etc. An odd number leaves a remainder when it is divided by 2. All those numbers having any one from 1, 3, 5, 7 and 9 at their ones places are also called odd numbers.)

So for Checking Whether number is even or odd we can use remainder function,so if number is even we have to print even else print odd


import java.util.Scanner;

import java.math.BigInteger;

class ChefBraveWarrior

public static void main(String []arg)

	Scanner in = new Scanner(System.in);
	BigInteger a = new BigInteger(in.next());

	BigInteger b = new BigInteger(in.next());
	BigInteger diff = a.subtract(b);





A C++ implementation and explanation would be nice dear. Please consider adding it. :slight_smile:

1 Like

okay i will,dont forget to upvote if u like all content

The numbers in your test cases go up to 1024. Check status code here and here. This is misleading because 1019 fits in unsigned long long int but a person using that would get WA. You should update either the test cases or the problem statement.

1 Like

Hey @meooow! Can you tell how did you find that the numbers in his test cases went upto 10^24??

I need karma points to ask my first questions. Please upvote me!!


I was surprised to get WA with unsigned long long so I made a few submissions that throw an exception if a specified limit is exceeded, and it turns out the max value is somewhere between 1023 and 1024.

1 Like

Wow!! How did you made a guess that max value was between that range? I can understand the part where its greater than 10^20 (overflow in long long int) but how did you precisely found the limit?

Trial and error :stuck_out_tongue:
You can see the two submission links, the one with limit 1023 gives RE but 1024 is accepted. You can do a manual binary search to narrow it down further if you have nothing to do at the moment XD

1 Like

LOL XDDDDDD. Oh God @meooow! You’re just…oh my…“Trial and Error” FTW …XDXDXD hahaha.

1 Like

okay meoow,xDDDDD