Category Archives: Mathematical

Segmented Sieve

Given a number n, print all primes smaller than n. For example, if the given number is 10, output 2, 3, 5, 7. A Naive approach is to run a loop from 0 to n-1 and check each number for primeness. A Better Approach is use Simple Sieve of Eratosthenes. Problems with Simple Sieve: The… Read More »

Check if a given number is Fancy

A fancy number is one which when rotated 180 degrees is the same. Given a number, find whether it is fancy or not. 180 degree rotations of 6, 9, 1, 0 and 8 are 9, 6, 1, 0 and 8 respectively Examples: Input: num = 96 Output: Yes If we rotate given number by 180,… Read More »