# Tag Archives: adhoc

## Spoj ABSP1 solution

SPOJ ABSP1 SOLUTION. SPOJ abs(A-B) I SOLUTION. Category: AdHoc In this question, for solution in one iteration, we need to calculate all the terms corresponding to each position of array in one step. This can be done if initially we find the sum of all the elements. Algorithm: Find sum of all the elements. (this is done… Read More »

## Spoj GEEKOUNT solution

Spoj GEEKOUNT Solution. Spoj EVEN COUNT Solution. Category: Maths, AdHoc, Formula We have to find the count of such numbers, between 2 given numbers, whose product of digits is even. Any number, in which any one digit is even, will come in this category. We will find all those numbers whose product of digits is… Read More »

## Spoj GAMES solution

Spoj GAMES solution. Spoj HOW MANY GAMES solution. Category: AdHoc, Number Theory Here we need to convert the given rational number into fraction. We find the denominator, and numerator, then find the GCD of numerator and denominator, Then denominator/GCD is the required answer. Since, we have a rational number, we enter the number as a string and… Read More »

## Spoj SPEED solution

Spoj SPEED solution. Spoj Circular Track Solution. Category: Number Theory,AdHoc, Maths, In this question, we need to tell the number of distinct points where the two entities meet. This is given by the formula. n=abs(Va−Vb)/abs(GCD(Va,Vb)) Spoj SPEED Solution code: Here is the working code: #include <bits/stdc++.h> using namespace std; /*Euclid’s GCD function*/ int GCD(int a,int b)… Read More »

## Spoj PR003004 solution

Spoj PR003004 solution. Spoj Digit Sum solution. Category: Formula, Maths, DP In this question we need to find the sum of digits of all numbers between A and B. This can be done in the following way. Algorithm: Find Sum of digits from 1 to B. Find Sum of digits from 1 to (A-1). Subtract… Read More »

## Spoj CPCRC1C solution

Spoj CPCRC1C solution. Spoj Sum of Digits solution. Category: Formula, Maths, DP In this question we need to find the sum of digits of all numbers between A and B. This can be done in the following way. Algorithm: Find Sum of digits from 1 to B. Find Sum of digits from 1 to (A-1). Subtract… Read More »

## Spoj DOTAA solution

Spoj DOTAA solution. Spoj DOTA HEROES solution. Category: AdHoc In this question we just need to check that if there are people whose together can sustain the attack from the towers. If we have N towers, then we need to some players with power such that they can take these attacks and still be alive. What… Read More »

## Spoj THEATRE solution

Spoj THEATRE solution. Spoj Movie Theatre Madness solution. Category: AdHoc, Stack In this question we need to print the product of the next greater values for all the people. This is easily done using stack. Maintain a variable prod, that has the final answer, then enter a value (val) from user, if stack is empty push… Read More »

## Spoj NY10A solution

Spoj NY10A solution. Spoj Penney Game Solution. Category: AdHoc,Hashing In this question, we are have to find the number of times that each combination occurs in a given input string. TTT, TTH, THT, THH, HTT, HTH, HHT and HHH We use and array of size 8 to store the number of occurrences of each permutation. We… Read More »

## Spoj IITKWPCB solution

Spoj IITKWPCB solution. Spoj Check the coprimeness solution. Category: Number Theory. (Easy) In this question, we need to print largest non-negative number less than or equal to floor (N/2) which is coprime to N. Two number a and b are considered to coprime if GCD(a, b) = 1. Here, what we do is simply start “i”from N/2… Read More »