Yearly Archives: 2014

Lightoj Problem-Sum of Consecutive Integers

Problem Link: Here Explanation: Let, k be the number of consecutive integers starting from x whose sum equals N.So we can write, x+(x+1)+……..+(x+k-1)=N ——–(1) or, kx+k*(k-1)/2=N or, 2kx+k^2-k=2N or, k(2x+k-1)=2N ———-(2) From equation (2) we can say, k is a

Posted in Lightoj, Math, Number Theory

SPOJ Inversion Count

Problem Summary: Let A[0…n – 1] be an array of n distinct positive integers. If i A[j] then the pair (i, j) is called an inversion of A. Given n and an array A your task is to find the

Posted in Binary Indexed Tree, SPOJ, UVA

Nim

Proof of the winning formula The soundness of the optimal strategy described above was demonstrated by C. Bouton. Theorem. In a normal Nim game, the player making the first move has a winning strategy if and only if the nim-sum

Posted in Game Theory

SRM-613(Div-2) 1000

Problem Statement Solution Analysis Code:

Posted in Favorite Problems, TopCoder

An Easy DP Problem-2 with Bitmask

Given N integers. Let Total subsets T=2N. How many subsets are available from T where the distinct integers are less than or equal to K. Sample Input: 4 2 (N,K) 1 2 3 4(A[i]) Sample Output: 11 Sample Input: 4

Posted in Dynamic Programming

Project Euler 16

What is the sum of the digits of the number 2^1000?

Posted in Number Theory, Project Euler