×

# EXOCODE5 - Editorial

 1 Problem Link-https://www.codechef.com/problems/EXOCODE5 DIFFICULTY:Easy-Medium 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 AUTHOR'S AND TESTER'S SOLUTIONS: 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); if(b.remainder(BigInteger.valueOf(2))==BigInteger.ZERO) { System.out.println(diff); System.out.println("even"); } else { System.out.println(diff); System.out.println("odd"); } }  } edit1-correction asked 15 Mar '17, 17:17 2★vivek96 533●2●21 accept rate: 8% 0★admin ♦♦ 19.8k●350●498●541 1 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) 1 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) 1 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★ 1 LOL XDDDDDD. Oh God @meooow! You're just...oh my..."Trial and Error" FTW ....XDXDXD hahaha. (15 Mar '17, 20:13) okay meoow,xDDDDD (16 Mar '17, 07:43) vivek962★ showing 5 of 7 show all

 2 I need karma points to ask my first questions. Please upvote me!! answered 15 Mar '17, 20:03 150●6 accept rate: 13%
 1 A C++ implementation and explanation would be nice dear. Please consider adding it. :-) answered 15 Mar '17, 18:11 15.5k●1●20●66 accept rate: 18% okay i will,dont forget to upvote if u like all content (15 Mar '17, 18:16) vivek962★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×15,852
×1,313
×347
×69
×50
×21

question asked: 15 Mar '17, 17:17

question was seen: 588 times

last updated: 20 Mar '17, 12:35