title-img


Flipping Coins

There are N coins kept on the table, numbered from 0 to N - 1. Initially, each coin is kept tails up. You have to perform two types of operations: 1) Flip all coins numbered between A and B inclusive. This is represented by the command "0 A B" 2) Answer how many coins numbered between A and B inclusive are heads up. This is represented by the command "1 A B". Input : The first line contains two integers, N and Q. Each of the next Q lines are either of the form "0 A B" or "1 A B" as m

View Solution →

Shopping Change - CodeChef

Chef went shopping and bought items worth X rupees (1≤X≤100). Unfortunately, Chef only has a single 100 rupees note. Since Chef is weak at maths, can you help Chef in calculating what money he should get back after paying 100 rupees for those items? Input Format First line will contain T, the number of test cases. Then the test cases follow. Each test case consists of a single line containing an integer X, the total price of items Chef purchased. Output Format For each test case,

View Solution →

Get Lowest Free - CodeChef

Chef goes to the supermarket to buy some items. Luckily there's a sale going on under which Chef gets the following offer: If Chef buys 3 items then he gets the item (out of those 3 items) having the lowest price as free. For e.g. if Chef bought 3 items with the cost 6, 2 and 4, then he would get the item with cost 2 as free. So he would only have to pay the cost of the other two items which will be 6+4=10. Chef buys 3 items having prices A, B and C respectively. What is the amount of mon

View Solution →

The product mystery - Codechef

Given two positive numbers B and C, what is the minimum positive value of A, such that A⋅B is divisible by C. Here, A⋅B denotes the value obtained when A is multiplied by B. Input Format The first line will contain an integer T - number of test cases. Then the test cases follow. The first and only line of each test case contains two integers B and C. Output Format For each test case, output the minimum value of A such that A⋅B is divisible by C. Constraints 1≤T≤105 1≤B,C≤1

View Solution →