Farley (leagues) sequence

definition:

  For any given one of the natural number n, the denominator is less than or equal to n irreducible proper fraction in ascending order, and add 0/1, after the last 1/1 before the first score by a fraction, the sequence referred to as n-level Farley number of columns, i.e. the number of thunder column-fraction in ascending order of between 0 and a number of columns, the number n the number of mine-stage process column is met when 1 <= a <<= n b && gcd ( a, number b) tuple (a, b) is the == 1 + 2 (0/1 and 1/1)

nature:

  1. In addition to the number of stage 1 thunder column method, the number of all ray method has an odd number of columns of elements, which elements lie directly in the middle of that must be 1/2.
  2. Ray number of columns n-stage process, when the two elements are adjacent a / b and c / d (a / b <c / d), the difference between these two numbers is 1 / bd, 1 is the minimum value of the difference / (n * (n-1)), a maximum of 1 / n ,, the difference between the first element (0/1) of the number of columns thunder and its successor, the last element (1/1) and the precursor to take a maximum value, and takes the second largest positive difference value between the middle of the element and its predecessor and successor elements 1/2 1 / (n * 2).
  3. Any two adjacent elements of a / b and c / d (a / b <c / d), to meet the b * c - a * d == 1
  4. Any three adjacent elements, the intermediate element == (+ precursor molecule elements subsequent element molecules) / (denominator precursor element subsequent element denominator +) (Note that to its simplest form)
  5. Set F (n) is the number of n-th stage number Ray column method, Phi (n) is the value of Euler function, then F (n) = F (n-1) + phi (n) (defined sequence considering Farley correctness apparently)
  6. N tends to infinity when n, the number of columns the number of mine-stage process comprising n elements tend 3 * n * n / (pi * pi) (pi = acos (-1))

structure:

  4 according to the nature of simple construction, Stern-Brocot tree is a data structure, the number of columns to mine construction method. Stern-Brocot tree from 0 (=  0 / 1 ) and 1 (=  1 / 1 ) starts, taking the middle fraction constituted Farey sequence, i.e. according to the nature of the structure 4.

Stern-Brocot tree generation rules:

HDU4556 Stern-Brocot Tree

The figure is a Stern-Brocot tree that generates rules are as follows:
  from the first row to the n-th row, every two adjacent rows of numbers a / b and c / d, to generate an intermediate number (a + c) / (b + d), placed in the next row. The score line (including 0 / 1,1 / 0) for about simplified minutes, then each row (including 0 / 1,1 / 0,1 / 1), two identical scores does not occur. If the molecule or the denominator exceeds n, then the score is removed, the remaining fraction, from small to large, to obtain the column F.

According to this thinking, the code is better written

#include <bits / STDC ++ H.>
 the using  namespace STD; 

int n-; 

void DFS ( int A1, int B1, int A2, int B2) // A1 / B1, A2 / B2 
{
     IF (B1 + B2> n-)
         return ; 
    DFS (A1, B1, A1 + A2, B1 + B2); // left to left small 
    the printf ( " % D /% D " , A1 + A2, B1 + B2); 
    DFS (A1 + A2, B1 + B2, A2, B2); // the right 
} 

int main () 
{ 
    Scanf ( "D% " , & n-); // Sequence Series 
    the printf ( " 0/1 " ); 
    DFS ( 0 , . 1 , . 1 , . 1 ); // can result from small to large outputs 
    the printf ( " 1/1 \ n- " ) ;
     return  0 ; 
}

 Correctness:

How to ensure that this approach is the most simple fraction generated?

3 and using the properties of mathematical induction is easy to prove

How to ensure that do not leak?

Not heavy: because orderly, therefore, is not heavy, orderly Why? Obviously, not obvious, then look at the code according to which the idea is clearly

Do not leak: Each score is from an upper bound and the next approach, similar dichotomy, clearly does not leak

example:

POJ2478 Farey Sequence 

POJ3090 Visible Lattice Points

Fraction HDU6624    (This problem extended Farley considered a number of columns, is seeking a minimum of two scores between the denominator of the fraction is the number)

 

Guess you like

Origin www.cnblogs.com/Zeronera/p/11372505.html