Problem Link http://www.spoj.com/problems/CUBEFR/ Problem Description In this problem,we need to find for a given number n whether it is cube free or not. If n is cube free,we need to print its position among cube free numbers. A number n is cube free if none of the divisors of n is a cube number. 1,2,3,4,5,6,7,9,10,11,12,13 […]

# Author: ankuragarwal

# SPOJ: TDPRIMES – Printing some primes

Problem Link http://www.spoj.com/problems/TDPRIMES/ Problem Description In this problem,we need to print 1st,101st,201st…….primes less than 10^8. Concepts Used This problem is based on prime sieve(Sieve of Eratosthenes).. Code #include<stdio.h> #include<vector> /*To check whether a number i is prime or not,we need to check a[i/2] or a[i>>1] whether it is true or false*/ #define isprime(i) (a[i>>1]) /*number […]

# SPOJ: CPRIME – Prime Number Theorem

Problem Link http://www.spoj.com/problems/CPRIME/ Problem Description In this problem,we need to find percentage error for prime number theorem ((pi(x)-lnx)/pi(x)) % where pi(x) =number of primes not greater than x. Concepts Used This problem is based on prime sieve(Sieve of Eratosthenes).. Code #include<stdio.h> #include<vector> #include<math.h> /*To check whether a number i is prime or not,we need to […]

# SPOJ: TDKPRIME – Finding the Kth Prime

Problem Link http://www.spoj.com/problems/TDKPRIME/ Problem Description In this problem, We need to print the value of kth prime(max value of k is 5000000) for a number of test cases. Concepts Used This problem is based on prime sieve(Sieve of Eratosthenes). Code #include<stdio.h> #include<vector> /*To check whether a number i is prime or not,we need to check […]

# SPOJ: PRIME1 – Prime Generator

Problem Link http://www.spoj.com/problems/PRIME1/ Problem Description In this problem, We need to print all the prime numbers between two given values m and n. Concepts Used This problem is based on prime sieve(Sieve of Eratosthenes). Code #include<stdio.h> void sieve(long long int,long long int,bool[],bool[]); int main() { long long int m,n; int t; /*scan number of test […]

# Prime Factorization(Using Prime Sieve)

Prime factorisation of a number is finding all the prime factors of a number. For example, prime factorisation of 120 can be written as: 120=2*2*2*3*5 One method for finding prime factorisation of a number is to check for each prime number(less than given number) whether it divides the given number or not. However,we can find […]

# Sieve of Eratosthenes(Prime Sieve)

Sieve of Eratosthenes is used to find all the prime numbers up to a given number N.This method is very efficient than the brute force method(Each number between 2 and N is checked to find if it has any other factors except 1 and itself). The basic concept behind Sieve of Eratosthenes is the fact […]

# Translation of a Line

Translation of line comes under the category of geometric transformations.In geometric transformations,the object is transformed relative to a stationary coordinate system or background.In 2D translation,the object is displaced along x and y direction and magnitude of displacement is specified by translation parameters tx and ty. In order to perform a sequence of transformations(translation,scaling,rotation or reflection) […]

# Cohen Sutherland Line Clipping Algorithm

Line Clipping Algorithms are used for clipping line with respect to a rectangle called as clipping window. Cohen Sutherland line clipping algorithm checks both the endpoints with four boundaries of rectangle(top,bottom,left and right) to decide whether the point lies inside or outside the four boundaries.This checking is done using a four bit code corresponding to […]

# Boundary-Fill Algorithm

Boundary-fill algorithm is used for region filling when the region is boundary-defined i.e. pixels having colour equal to boundary_col comprise the boundary of region.This algorithm starts with a seed pixel inside the region which is the starting point for the recursive algorithm. The algorithm checks to see if pixel is boundary pixel(defined by boundary_col) or […]