You are not logged in. Please login at to post your questions!


EXOCODE5 - Editorial

Problem Link-



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-

IN C/C++ -

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(;

    BigInteger a = new BigInteger(;

    BigInteger b = new BigInteger(;

    BigInteger diff = a.subtract(b);





asked 15 Mar '17, 17:17

vivek96's gravatar image

accept rate: 7%

edited 20 Mar '17, 12:35

admin's gravatar image

0★admin ♦♦


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.

(15 Mar '17, 19:56) meooow ♦6★

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

(15 Mar '17, 20:01) vijju123 ♦5★

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.

(15 Mar '17, 20:05) meooow ♦6★

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?

(15 Mar '17, 20:07) vijju123 ♦5★

Trial and error :P 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

(15 Mar '17, 20:11) meooow ♦6★

LOL XDDDDDD. Oh God @meooow! You're just...oh my..."Trial and Error" FTW ....XDXDXD hahaha.

(15 Mar '17, 20:13) vijju123 ♦5★

okay meoow,xDDDDD

(16 Mar '17, 07:43) vivek962★
showing 5 of 7 show all

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


answered 15 Mar '17, 20:03

akshaym_96's gravatar image

accept rate: 13%

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


answered 15 Mar '17, 18:11

vijju123's gravatar image

5★vijju123 ♦
accept rate: 19%

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

(15 Mar '17, 18:16) vivek962★
PREREQUISITES-Big-Integer,Basic Java Programming

This is wrong dear!! You cannot have a pre-requisite of "knowing this programming language" for any problem. Just because you solved it using big integers in java doesn't mean its pre-requisite. In python, you need not know anything, it handles big numbers automatically. In C/C++, you need to know array and stuff to do the problem.

Also, I appreciate your java approach and you introducing Big Integers, its good for JAVA beginners. But it'd be better if you can also give a C++ approach to the question, as it requires a clever implementation which would help beginners. :)


answered 15 Mar '17, 18:02

vijju123's gravatar image

5★vijju123 ♦
accept rate: 19%

edited 15 Mar '17, 18:06

Dear thats why it is closed contest and almost everyone knows java there.i am also agree with u in solving this question in other languages.

(15 Mar '17, 18:13) vivek962★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 15 Mar '17, 17:17

question was seen: 484 times

last updated: 20 Mar '17, 12:35