# heartin's blog

## [Problems] Summary of Problems Based on Mathematics and Probability

1. Write methods to implement the multiply, substract and divide operations for integers, using only the add operator.

• Hint:

• a + b => a + negate(b)

• a * b => add b a times

• x = a / b => a = bx.

2. Find the kth number such that the only prime factors are 3,5 and 7

## [Algorithm+Implementation] Sieve of Eratosthenes Algorithm for Finding all Prime Numbers Up To Any Given Limit

In mathematics, the sieve of Eratosthenes is an algorithm for finding all prime numbers up to any given limit.

It does so by iteratively marking as composite (i.e., not prime) the multiples of each prime, starting with the multiples of 2.

It works on the principle that all non-prime numbers are divisible by a prime number.

## [Problems] Summary of Problems Based on Sequences

Problems related to sequence generation and finding if an element fits in a sequence.

### Problems

1. Generate the below sequence with n elements.

• 1, 10, 11, 100, 110, 111, 1000.

• Note:

• Every element in the sequence is a series of 1 or more 1's followed by zero or more 0's.

• For example 101 is an invalid element and does not belong to the sequence, but 1, 10, 11, 100, 110, 111, 1000 etc. belong to the sequence.

LinkedHashMap extends HashMap and has a predictable iteration order.

1. LinkedHashMap implementation maintains a doubly-linked list running through all of its entries.

2. The doubly linked list maintained by the LinkedHashMap implementation defines the iteration ordering.

3. By default, the order is the order in which keys were inserted into the map.

## [Assignment Problem] Multi-threaded Series Printer

### Problem

Write a multi-threaded program to print data from four series of data in alternating order.

There are four series of data are as below:

Series 1:              0,            4,            8,            12,          …

Series2:               1,            5,            9,            13,          …

Series3:               2,            6,            10,          14,          …