The Josephus Problem

Introduction

The Josephus Problem is a count-out game which is regarded as a theoretical problem in Computer Science or Mathematics. In this game, n people stand in a circle s is the starting number of people. s is holding a sword where s kills s+k-1‘th people from his position and gives his sword to s+k‘th people. Thus s+k becomes new s.

Read More

How many regions do N lines divide a plane?

Explanations:

N straight lines are drawn on a plane paper. Each line intersects with rest all lines. That means N‘th line intersects N-1 lines. You can assume infinite number of lines can be drawn on that paper. You have to find total regions after N lines are drawn. An image is given below to understand the problem clearly.

Read More

The Tower of Hanoi Solution

Definition:

The Tower of Hanoi problem is a puzzle which can be solved by mathematically and can be implemented in programming code as well. The tower is also called Tower of Brahma or Lucas’ Tower. In this, game there are three pegs and one one of them hold n disks. n disks are ordered from higher radius to lower radius from the bottom to top.

Read More

UVA 11876 - N + NOD (N)

Description:

For a number N, first have to calculate N-1+divisors(N-1) & store it in array (e.g. arr[i]=arr[i-1]+divisors(arr[i-1])).
Make a sequence from 1 to until arr[i] becomes greater than 1000000. Then you will be given two numbers A & B, and you will have to find the number of integers from the above sequence which lies within the range [A,B].

Hints = No critical case. Easy problem.

Read More