State Fermat algorithm

The basic Fermat algorithm is as follows:

Assume that n is an odd positive integer. Set c = [√n] (`ceiling of √n '). Then we consider in turn the numbers

c2 - n; (c+1)2 - n; (c+2)2 - n.....

until a perfect square is found. If this occurs at the term (c+k)2 - n, then putting a = c+k we have

a2 - n = (c+k)2 - n = b2;

say, and then n = a2 - b2, as desired.

This process will terminate in the worst case when a = (n+1)/2, since

n = [(n+1)/2]2 - [(n-1)/2]2
 
In particular, the number of steps taken will be at worst

(n+1)/2 - [√n] +1 = O(n)

   Related Questions in Mathematics

  • Q : Explain trading of call options Explain

    Explain trading of call options.

  • Q : Profit-loss based problems A leather

    A leather wholesaler supplies leather to shoe companies. The manufacturing quantity requirements of leather differ depending upon the amount of leather ordered by the shoe companies to him. Due to the volatility in orders, he is unable to precisely predict what will b

  • Q : Set Theory & Model of a Boolean Algebra

    II. Prove that Set Theory is a Model of a Boolean Algebra The three Boolean operations of Set Theory are the three set operations of union (U), intersection (upside down U), and complement ~.  Addition is set

  • Q : State Measuring complexity Measuring

    Measuring complexity: Many algorithms have an integer n, or two integers m and n, as input - e.g., addition, multiplication, exponentiation, factorisation and primality testing. When we want to describe or analyse the `easiness' or `hardness' of the a

  • Q : Problem on Prime theory Suppose that p

    Suppose that p and q are different primes and n = pq. (i) Express p + q in terms of Ø(n) and n. (ii) Express p - q in terms of p + q and n. (iii) Expl

  • Q : Problem on mass balance law Using the

    Using the mass balance law approach, write down a set of word equations to model the transport of lead concentration. A) Draw a compartmental model to represent  the diffusion of lead through the lungs and the bloodstream.

  • Q : Explain Factorisation by trial division

    Factorisation by trial division: The essential idea of factorisation by trial division is straightforward. Let n be a positive integer. We know that n is either prime or has a prime divisor less than or equal to √n. Therefore, if we divide n in

  • Q : What is Big-O hierarchy The big-O

    The big-O hierarchy: A few basic facts about the big-O behaviour of some familiar functions are very important. Let p(n) be a polynomial in n (of any degree). Then logbn is O(p(n)) and p(n) is O(an<

  • Q : Properties of a group How can we say

    How can we say that the pair (G, o) is a group. Explain the properties which proof it.

  • Q : Explain Black–Scholes model Explain

    Explain Black–Scholes model.

©TutorsGlobe All rights reserved 2022-2023.