--%>

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 : Examples of groups Examples of groups:

    Examples of groups: We now start to survey a wide range of examples of groups (labelled by (A), (B), (C), . . . ). Most of these come from number theory. In all cases, the group axioms should be checked. This is easy for almost all of the examples, an

  • Q : Simulation with Arena An office of

    An office of state license bureau has two types of arrivals. Individuals interested in purchasing new plates are characterized to have inter-arrival times distributed as EXPO(6.8) and service times as TRIA(808, 13.7, 15.2); all times are in minutes. Individuals who want to renew or apply for a new d

  • Q : Explain Black–Scholes model Explain

    Explain Black–Scholes model.

  • Q : Problem on inventory merchandise AB

    AB Department Store expects to generate the following sales figures for the next three months:                            

  • 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 : What is limit x tends to 0 log(1+x)/x

    What is limit x tends to 0  log(1+x)/x to the base a?

  • Q : How do it? integral e^(-t)*e^(tz) t

    integral e^(-t)*e^(tz) t between 0 and infinity for Re(z)<1

  • Q : Problem on Linear equations Anny, Betti

    Anny, Betti and Karol went to their local produce store to bpought some fruit. Anny bought 1 pound of apples and 2 pounds of bananas and paid $2.11.  Betti bought 2 pounds of apples and 1 pound of grapes and paid $4.06.  Karol bought 1 pound of bananas and 2

  • Q : Containee problem For queries Q 1 and Q

    For queries Q1 and Q2, we say Q1 is containedin Q2, denoted Q1 C Q2, iff Q1(D) C Q2

  • Q : Problem on augmented matrix Consider

    Consider the following system of linear equations.  (a) Write out t