The Wayback Machine - https://web.archive.org/web/20240828112551/https://www.geeksforgeeks.org/lucas-primality-test/
Open In App

Lucas Primality Test

Last Updated : 29 Jul, 2022
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow
Companies:
Show Topics
Solve Problem
Basic
22.2%
2.7L

A number p greater than one is prime if and only if the only divisors of p are 1 and p. First few prime numbers are 2, 3, 5, 7, 11, 13, …
The Lucas test is a primality test for a natural number n, it can test primality of any kind of number.
It follows from Fermat’s Little Theorem: If p is prime and a is an integer, then a^p is congruent to a (mod p )

Lucas’ Test : A positive number n 
is prime if there exists an integer a (1 < a < n) such that : 

a^{{n-1}}\ \equiv \ 1{\pmod n}

And for every prime factor q of (n-1),

a^{{({n-1})/q}}\ \not \equiv \ 1{\pmod n}

Examples : 

Input :  n = 7
Output : 7 is Prime
Explanation : let's take a = 3, 
then 3^6 % 7 = 729 % 7 = 1 (1st 
condition satisfied). Prime factors 
of 6 are 2 and 3,
3^(6/2) % 7 = 3^3 % 7 = 27 % 7 = 6
3^(6/3) % 7 = 3^2 % 7 = 9 % 7 = 2
Hence, 7 is Prime  

Input :  n = 9
Output : 9 is composite
Explanation : Let's take a = 2,
then 2^8 % 9 = 256 % 9 = 4
Hence 9 is composite 
lucasTest(n):
If n is even
    return composite
Else
   Find all prime factors of n-1
   for i=2 to n-1
      pick 'a' randomly in range [2, n-1]
      if a^(n-1) % n not equal 1:
          return composite
      else 
          // for all q, prime factors of (n-1)
          if a^(n-1)/q % n not equal 1 
             return prime
   Return probably prime


Problems Associated with Lucas’s test are : 

  • Knowing all of the prime factors of n-1
  • Finding an appropriate choice for a

C++

// C++ Program for Lucas Primality Test
#include <bits/stdc++.h>
using namespace std;
 
// function to generate prime factors of n
void primeFactors(int n, vector<int>& factors)
{
    // if 2 is a factor
    if (n % 2 == 0)
        factors.push_back(2);
    while (n % 2 == 0)
        n = n / 2;
         
    // if prime > 2 is factor
    for (int i = 3; i <= sqrt(n); i += 2) {
        if (n % i == 0)
            factors.push_back(i);
        while (n % i == 0)
            n = n / i;
    }
    if (n > 2)
    factors.push_back(n);
}
 
// this function produces power modulo
// some number. It can be optimized to
// using
int power(int n, int r, int q)
{
    int total = n;
    for (int i = 1; i < r; i++)
        total = (total * n) % q;
    return total;
}
 
string lucasTest(int n)
{
    // Base cases
    if (n == 1)
        return "neither prime nor composite";
    if (n == 2)
        return "prime";
    if (n % 2 == 0)
        return "composite1";
         
         
    // Generating and storing factors
    // of n-1
    vector<int> factors;
    primeFactors(n - 1, factors);
 
    // Array for random generator. This array
    // is to ensure one number is generated
    // only once
    int random[n - 3];
    for (int i = 0; i < n - 2; i++)
        random[i] = i + 2;
         
    // shuffle random array to produce randomness
    shuffle(random, random + n - 3,
            default_random_engine(time(0)));
 
    // Now one by one perform Lucas Primality
    // Test on random numbers generated.
    for (int i = 0; i < n - 2; i++) {
        int a = random[i];
        if (power(a, n - 1, n) != 1)
            return "composite";
 
        // this is to check if every factor
        // of n-1 satisfy the condition
        bool flag = true;
        for (int k = 0; k < factors.size(); k++) {
            // if a^((n-1)/q) equal 1
            if (power(a, (n - 1) / factors[k], n) == 1) {
                flag = false;
                break;
            }
        }
 
        // if all condition satisfy
        if (flag)
            return "prime";
    }
    return "probably composite";
}
 
// Driver code
int main()
{
    cout << 7 << " is " << lucasTest(7) << endl;
    cout << 9 << " is " << lucasTest(9) << endl;
    cout << 37 << " is " << lucasTest(37) << endl;
    return 0;
}

                    

Java

// Java Program for Lucas Primality Test
import java.util.*;
 
class GFG {
    static ArrayList<Integer> factors
        = new ArrayList<Integer>();
   
    // function to generate prime factors of n
    static ArrayList<Integer> primeFactors(int n)
    {
        // if 2 is a factor
        if (n % 2 == 0)
            factors.add(2);
        while (n % 2 == 0)
            n = n / 2;
 
        // if prime > 2 is factor
        for (int i = 3; i <= Math.sqrt(n); i += 2) {
            if (n % i == 0)
                factors.add(i);
            while (n % i == 0)
                n = n / i;
        }
        if (n > 2)
            factors.add(n);
        return factors;
    }
 
    // this function produces power modulo
    // some number. It can be optimized to
    // using
    static int power(int n, int r, int q)
    {
        int total = n;
        for (int i = 1; i < r; i++)
            total = (total * n) % q;
        return total;
    }
 
    static String lucasTest(int n)
    {
        // Base cases
        if (n == 1)
            return "neither prime nor composite";
        if (n == 2)
            return "prime";
        if (n % 2 == 0)
            return "composite1";
 
        // Generating and storing factors
        // of n-1
        primeFactors(n - 1);
 
        // Array for random generator. This array
        // is to ensure one number is generated
        // only once
        int[] random = new int[n - 2];
        for (int i = 0; i < n - 2; i++)
            random[i] = i + 2;
 
        // shuffle random array to produce randomness
        Collections.shuffle(Arrays.asList(random));
 
        // Now one by one perform Lucas Primality
        // Test on random numbers generated.
        for (int i = 0; i < n - 2; i++) {
            int a = random[i];
            if (power(a, n - 1, n) != 1)
                return "composite";
 
            // this is to check if every factor
            // of n-1 satisfy the condition
            boolean flag = true;
            for (i = 0; i < factors.size(); i++) {
                // if a^((n-1)/q) equal 1
                if (power(a, (n - 1) / factors.get(i), n) == 1) {
                    flag = false;
                    break;
                }
            }
 
            // if all condition satisfy
            if (flag)
                return "prime";
        }
        return "probably composite";
    }
 
    // Driver code
    public static void main(String[] args)
    {
        System.out.println(7 + " is " + lucasTest(7));
        System.out.println(9 + " is " + lucasTest(9));
        System.out.println(37 + " is " + lucasTest(37));
    }
}
 
// This code is contributed by phasing17

                    

Python3

# Python3 program for Lucas Primality Test
import random
import math
 
# Function to generate prime factors of n
def primeFactors(n, factors):
     
    # If 2 is a factor
    if (n % 2 == 0):
        factors.append(2)
         
    while (n % 2 == 0):
        n = n // 2
         
    # If prime > 2 is factor
    for i in range(3, int(math.sqrt(n)) + 1, 2):
        if (n % i == 0):
            factors.append(i)
             
        while (n % i == 0):
            n = n // i
             
    if (n > 2):
        factors.append(n)
         
    return factors
     
# This function produces power modulo
# some number. It can be optimized to
# using
def power(n, r, q):
     
    total = n
     
    for i in range(1, r):
        total = (total * n) % q
         
    return total
  
def lucasTest(n):
  
    # Base cases
    if (n == 1):
        return "neither prime nor composite"
    if (n == 2):
        return "prime"
    if (n % 2 == 0):
        return "composite1"
          
    # Generating and storing factors
    # of n-1
    factors = []
     
    factors = primeFactors(n - 1, factors)
  
    # Array for random generator. This array
    # is to ensure one number is generated
    # only once
    rand = [i + 2 for i in range(n - 3)]
          
    # Shuffle random array to produce randomness
    random.shuffle(rand)
  
    # Now one by one perform Lucas Primality
    # Test on random numbers generated.
    for i in range(n - 2):
        a = rand[i]
         
        if (power(a, n - 1, n) != 1):
            return "composite"
  
        # This is to check if every factor
        # of n-1 satisfy the condition
        flag = True
         
        for k in range(len(factors)):
             
            # If a^((n-1)/q) equal 1
            if (power(a, (n - 1) // factors[k], n) == 1):
                flag = False
                break
  
        # If all condition satisfy
        if (flag):
            return "prime"
     
    return "probably composite"
     
# Driver code
if __name__=="__main__":
     
    print(str(7) + " is " + lucasTest(7))
    print(str(9) + " is " + lucasTest(9))
    print(str(37) + " is " + lucasTest(37))
 
# This code is contributed by rutvik_56

                    

C#

// C# Program for Lucas Primality Test
 
using System;
using System.Linq;
using System.Collections.Generic;
 
 
class GFG
{
    static List<int> factors = new List<int>();
    // function to generate prime factors of n
    static List<int> primeFactors(int n)
    {
        // if 2 is a factor
        if (n % 2 == 0)
            factors.Add(2);
        while (n % 2 == 0)
            n = n / 2;
             
        // if prime > 2 is factor
        for (int i = 3; i <= Math.Sqrt(n); i += 2) {
            if (n % i == 0)
                factors.Add(i);
            while (n % i == 0)
                n = n / i;
        }
        if (n > 2)
        factors.Add(n);
        return factors;
    }
     
    // this function produces power modulo
    // some number. It can be optimized to
    // using
    static int power(int n, int r, int q)
    {
        int total = n;
        for (int i = 1; i < r; i++)
            total = (total * n) % q;
        return total;
    }
     
    static string lucasTest(int n)
    {
        // Base cases
        if (n == 1)
            return "neither prime nor composite";
        if (n == 2)
            return "prime";
        if (n % 2 == 0)
            return "composite1";
             
             
        // Generating and storing factors
        // of n-1
        primeFactors(n - 1);
     
        // Array for random generator. This array
        // is to ensure one number is generated
        // only once
        int[] random = new int[n - 2];
        for (int i = 0; i < n - 2; i++)
            random[i] = i + 2;
             
        // shuffle random array to produce randomness
        Random rand = new Random();
        random = random.OrderBy(x => rand.Next()).ToArray();
     
        // Now one by one perform Lucas Primality
        // Test on random numbers generated.
        for (int i = 0; i < n - 2; i++) {
            int a = random[i];
            if (power(a, n - 1, n) != 1)
                return "composite";
     
            // this is to check if every factor
            // of n-1 satisfy the condition
            bool flag = true;
            foreach (var factor in factors) {
                // if a^((n-1)/q) equal 1
                if (power(a, (n - 1) / factor, n) == 1) {
                    flag = false;
                    break;
                }
            }
     
            // if all condition satisfy
            if (flag)
                return "prime";
        }
        return "probably composite";
    }
     
    // Driver code
    public static void Main(string[] args)
    {
        Console.WriteLine(7 + " is " + lucasTest(7));
        Console.WriteLine(9 + " is " + lucasTest(9));
        Console.WriteLine(37 + " is " + lucasTest(37));
    }
}
 
 
// This code is contributed by phasing17

                    

Javascript

// JavaScript Program for Lucas Primality Test
 
// A function to shuffle the array.
function shuffle(arr){
    for(let i = arr.length-1; i>0;i--){
        // have a random index from [0, arr.length-1]
        let j = Math.floor(Math.random() * (i+1));
         
        // swap the original and random index element
        let temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
    return arr;
}
 
// function to generate prime factors of n
function primeFactors(n, factors) {
    // if 2 is a factor
    if (n % 2 == 0){
        factors.push(2);
    }
         
    while (n % 2 == 0){
        n = n / 2;
    }
                 
    // if prime > 2 is factor
    for (let i = 3; i <= Math.sqrt(n); i += 2) {
        if (n % i == 0){
            factors.push(i);
        }
             
        while (n % i == 0){
            n = n / i;
        }        
    }
    if (n > 2){
        factors.push(n);
    } 
}
 
// this function produces power modulo
// some number. It can be optimized to
// using
function power(n, r, q) {
    let total = n;
    for (let i = 1; i < r; i++){
        total = (total * n) % q;
    }     
    return total;
}
 
function lucasTest(n) {
     
    // Base cases
    if (n == 1){
        return "neither prime nor composite";
    }     
    if (n == 2){
       return "prime"; 
    }     
    if (n % 2 == 0){
        return "composite1";
    }
                
    // Generating and storing factors
    // of n-1
    const factors = [];
    primeFactors(n - 1, factors);
 
    // Array for random generator. This array
    // is to ensure one number is generated
    // only once
    const random = [];
    for (let i = 0; i < n - 2; i++){
        // random[i] = i + 2;
        random.push(i+2);
    }
         
    // shuffle random array to produce randomness
    shuffle(random);
 
    // Now one by one perform Lucas Primality
    // Test on random numbers generated.
    for (let i = 0; i < n - 2; i++) {
        let a = random[i];
        if (power(a, n - 1, n) != 1){
            return "composite";      
        }
             
        // this is to check if every factor
        // of n-1 satisfy the condition
        let flag = true;
        for (let k = 0; k < factors.length; k++) {
            // if a^((n-1)/q) equal 1
            if (power(a, (n - 1) / factors[k], n) == 1) {
                flag = false;
                break;
            }
        }
 
        // if all condition satisfy
        if (flag){
            return "prime";
        }
             
    }
    return "probably composite";
}
 
// Driver code
{
    console.log( 7 + " is " + lucasTest(7));
    console.log( 9 + " is " + lucasTest(9));
    console.log( 37 + " is " + lucasTest(37));
    return 0;
}
 
// The code is contributed by Gautam goel (gautamgoel962)
Javascript

                    

Output:

7 is prime
9 is composite
37 is prime

Time Complexity: O(nlogn)

Auxiliary Space: O(n)

This method is quite complicated and inefficient as compared to other primality tests. And the main problems are factors of ‘n-1’ and choosing appropriate ‘a’.

Other Primality tests:



Previous Article
Next Article

Similar Reads

Primality Test using Lucas-Lehmer Series
In this article, we will discuss the Lucas-Lehmer series which is used to check the primality of prime numbers of the form 2p - 1 where p is an integer. First, let's see what is Lucas-Lehmer series. The Lucas-Lehmer series can be expressed as : [Tex]\[s_i = \left \{ \begin{tabular}{c} 4 \hspace{1.4cm} when i = 0; \\ s_{i-1}^2 - 2 \hspace{.5cm} othe
11 min read
AKS Primality Test
There are several primality test available to check whether the number is prime or not like Fermat's Theorem, Miller-Rabin Primality test and alot more. But problem with all of them is that they all are probabilistic in nature. So, here comes one another method i.e AKS primality test (Agrawal–Kayal–Saxena primality test) and it is deterministically
11 min read
Vantieghems Theorem for Primality Test
Vantieghems Theorem is a necessary and sufficient condition for a number to be prime. It states that for a natural number n to be prime, the product of [Tex]2^i - 1 [/Tex]where [Tex]0 &lt; i &lt; n [/Tex], is congruent to [Tex]n~(mod~(2^n - 1)) [/Tex]. In other words, a number n is prime if and only if.[Tex]{\displaystyle \prod _{1\leq i\leq n-1}\l
4 min read
Primality test for the sum of digits at odd places of a number
Given an integer 'n', the task is to check whether the sum of digits at the odd positions (from right to left) is prime or not. If it is prime then, print "YES" or "NO" otherwise.Examples: Input: n = 123 Output: NO As, 1 + 3 = 4 is not prime.Input: n = 42 Output: YES Since, 2 is a prime. Approach: First, find the sum of the digits which are at odd
7 min read
Introduction to Primality Test and School Method
Given a positive integer, check if the number is prime or not. A prime is a natural number greater than 1 that has no positive divisors other than 1 and itself. Examples of the first few prime numbers are {2, 3, 5, ...}Examples : Input: n = 11Output: true Input: n = 15Output: false Input: n = 1Output: false Recommended PracticePrime NumberTry It! S
11 min read
Fermat Method of Primality Test
Given a number n, check if it is prime or not. We have introduced and discussed the School method for primality testing in Set 1.Introduction to Primality Test and School MethodIn this post, Fermat's method is discussed. This method is a probabilistic method and is based on Fermat's Little Theorem. Fermat's Little Theorem: If n is a prime number, t
10 min read
Primality Test | Set 3 (Miller–Rabin)
Given a number n, check if it is prime or not. We have introduced and discussed School and Fermat methods for primality testing.Primality Test | Set 1 (Introduction and School Method) Primality Test | Set 2 (Fermat Method)In this post, the Miller-Rabin method is discussed. This method is a probabilistic method ( like Fermat), but it is generally pr
15+ min read
Solovay-Strassen method of Primality Test
We have already been introduced to primality testing in the previous articles in this series. Introduction to Primality Test and School MethodFermat Method of Primality TestPrimality Test | Set 3 (Miller–Rabin) The Solovay–Strassen primality test is a probabilistic test to determine if a number is composite or probably prime. Before diving into the
15+ min read
String with frequency of characters in Lucas Sequence
Given a string 'str' containing lowercase English alphabets, the task is to find whether the frequencies of the characters of the string are in Lucas sequence or not. You are free to arrange the frequency numbers in any way, in order to form the Lucas sequence. If possible then print YES otherwise NO. Lucas Sequence. Note: All the frequencies must
8 min read
Longest sub-sequence of array containing Lucas numbers
Given an array arr[] of N elements, the task is to find the length of the longest sub-sequence in arr[] such that all the elements of the sequence are Lucas Numbers.Examples: Input: arr[] = {2, 3, 55, 6, 1, 18} Output: 4 1, 2, 3 and 18 are the only elements from the Lucas sequence. Input: arr[] = {22, 33, 2, 123} Output: 2 Approach: Find the maximu
6 min read
Sum of numbers from 1 to N which are in Lucas Sequence
Given a number N. The task is to find the sum of numbers from 1 to N, which are present in the Lucas Sequence. The Lucas numbers are in the following integer sequence: 2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123 ...... Examples: Input : N = 10 Output : 17 Input : N = 5 Output : 10 Approach: Loop through all the Lucas numbers which are less than the give
4 min read
Compute nCr % p | Set 4 (Chinese Remainder theorem with Lucas Theorem)
Given three numbers n, r and p, the task is to compute the value of nCr % p. Note: p is a square-free number and the largest prime factor of p ≤ 50. Examples: Input: n = 10, r = 2, p = 13Output: 6Explanation: 10C2 is 45 and 45 % 13= 6 Input: n = 6, r = 2, p = 13Output: 2 Approach: We have already discussed several other approaches of this problem.
10 min read
Compute nCr%p using Lucas Theorem
Given three numbers n, r and p, compute the value of nCr mod p. Examples: Input: n = 10, r = 2, p = 13 Output: 6 Explanation: 10C2 is 45 and 45 % 13 is 6. Input: n = 1000, r = 900, p = 13 Output: 8 We strongly recommend referring below post as a prerequisite of this.Compute nCr % p | Set 1 (Introduction and Dynamic Programming Solution)We have intr
12 min read
Lucas Numbers
Lucas numbers are similar to Fibonacci numbers. Lucas numbers are also defined as the sum of its two immediately previous terms. But here the first two terms are 2 and 1 whereas in Fibonacci numbers the first two terms are 0 and 1 respectively. Mathematically, Lucas Numbers may be defined as:[Tex]{\displaystyle L_{n}:={\begin{cases}2&amp;{\text{if
6 min read
Jacobsthal and Jacobsthal-Lucas numbers
Jacobsthal numbersThe Jacobsthal numbers are the numbers obtained by the Uns in the Lucas sequence with P=1 and Q=-2, corresponding to a = 2 and b = -1. Jacobsthal numbers are defined by the recurrence relation: [Tex]{\displaystyle J_{n}=\left\{\begin{matrix} 0 &amp; &amp; if n=0\\1&amp;&amp;ifn=1 \\ J_{n-1} + 2J_{n-2}&amp;&amp;ifn&gt;1 \end{matrix
15+ min read
Mathematical Algorithms - Prime numbers and Primality Tests
What is Prime Number?A prime number is a natural number greater than 1 that is divisible by only 1 and the number itself. In other words, the prime number can be defined as a positive integer greater than that has exactly two factors, 1 and the number itself. First 10 prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29. Note: 1 is neither a prime
3 min read
Analysis of test data using K-Means Clustering in Python
This article demonstrates an illustration of K-means clustering on a sample random data using open-cv library. Pre-requisites: Numpy, OpenCV, matplot-lib Let's first visualize test data with Multiple Features using matplot-lib tool. # importing required tools import numpy as np from matplotlib import pyplot as plt # creating two test data X = np.ra
2 min read
Test case generator for Tree using Disjoint-Set Union
In this article, we will generate test cases such that given set edges form a Tree. Below are the two conditions of the Tree: It should have one less edge than the number of vertices.There should be no cycle in it. Approach: The idea is to run a loop and add one edge each time that is generated randomly, and for adding each edge we will check wheth
11 min read
Kruskal Wallis Test
Kruskal Wallis Test: It is a nonparametric test. It is sometimes referred to as One-Way ANOVA on ranks. It is a nonparametric alternative to One-Way ANOVA. It is an extension of the Man-Whitney Test to situations where more than two levels/populations are involved. This test falls under the family of Rank Sum tests. It depends on the ranks of the s
4 min read
Friedman Test
Friedman Test: It is a non-parametric test alternative to the one way ANOVA with repeated measures. It tries to determine if subjects changed significantly across occasions/conditions. For example:- Problem-solving ability of a set of people is the same or different in Morning, Afternoon, Evening. It is used to test for differences between groups w
5 min read
Test Case Generation | Set 6 (Random Unweighted Binary Tree)
Generating Random Unweighted Binary Tree: Since this is a tree, the test data generation plan is such that no cycle gets formed.The number of edges is one less than the number of vertices.For each RUN, first print the count of nodes say, N and the next N - 1 lines are of the form (a, b) where a is the parent of b.Each node contains at most 2 childr
10 min read
Paired T-Test - A Detailed Overview
Student’s t-test or t-test is the statistical method used to determine if there is a difference between the means of two samples. The test is often performed to find out if there is any sampling error or unlikeliness in the experiment. This t-test is further divided into 3 types based on your data and result need. The types are: One sample t-test:
5 min read
Tukey-Kramer Test for Post Hoc Analysis
If in ANOVA test we come to a conclusion that we have to reject our null hypothesis(H0) and then we know that some treatment or factor level means are different and we wish to find them then we proceed to do post hoc analysis with Tukey's test to find which pair is different. This method is a multiple comparison method. About: Used to tell about po
2 min read
Generating Test Cases (generate() and generate_n() in C++)
Generating test cases for array programs can be a cumbersome process. But the generate and generate_n functions in the STL (Standard Template Library), come handy to populate the array with random values. generate() The generate functions assigns random values provided by calling the generator function 'gen' to the elements in the range [begin, end
2 min read
Test Case Generation | Set 1 (Random Numbers, Arrays and Matrices)
The test cases are an extremely important part of any "Software/Project Testing Process". Hence this Set will be very important for all aspiring software developers. The following are the programs to generate test cases. Generating Random Numbers C/C++ Code // A C++ Program to generate test cases for // random number #include&lt;bits/stdc++.h&gt; u
12 min read
Inmobi Interview Experience | Set 5 (Through College Test)
I recently got an opportunity of being interviewed at Inmobi after getting shortlisted for the Inmobi codies test. I was called for onsite interviews at their Bangalore office. The process consisted of 3 technical rounds and 1 HR round. Round 1: Tell me about yourself Discussion on my current work and previous projects. Detect loop in a linked list
3 min read
Test Case Generation | Set 2 ( Random Characters, Strings and Arrays of Random Strings)
Set 1 (Random Numbers, Arrays and Matrices) Generating Random Characters C/C++ Code // A C++ Program to generate test cases for // random characters #include&lt;bits/stdc++.h&gt; using namespace std; // Define the number of runs for the test data // generated #define RUN 5 // Define the range of the test data generated // Here it is 'a' to 'z' #def
11 min read
Test Case Generation | Set 3 (Unweighted and Weighted Trees)
Generating Random Unweighted Trees Since this is a tree, the test data generation plan is such that no cycle gets formed.The number of edges is one less than the number of verticesFor each RUN we first print the number of vertices - NUM first in a new separate line and the next NUM-1 lines are of the form (a b) where a is the parent of b C/C++ Code
15+ min read
How to prepare for Google Asia Pacific University (APAC) Test ?
Google Asia Pacific University Test, also referred to as Google APAC, is perhaps the best opportunity for a student enrolled in higher education institutes in the APAC region to mark a place in the big shot in the IT Sector - Google. Registration details Go to the Google APAC Website and click on participate.Once you login from your Google account,
4 min read
CSES Solutions - Point Location Test
There is a line that goes through the points p1 = (x1,y1) and p2 = (x2,y2). There is also a point p3 = (x3,y3). Your task is to determine whether p3 is located on the left or right side of the line or if it touches the line when we are looking from p1 to p2. Example: Input: x1 = 1, y1 = 1, x2 = 5, y2 = 3, x3 = 2, y3 = 3Output: LEFT Input: x1 = 1, y
5 min read