<p>A non-algorithmic way of finding the position <em>t</em> of a fraction in the Farey sequence of order <em>n</em>>1 is shown in Remark 7.10(ii)(a) of the <a href="http://arxiv.org/abs/math/0411026" rel="nofollow">paper</a>, under <em>m:=n</em>-1, where mu-bar stands for the number-theoretic Mobius function on positive integers taking values from the set {-1,0,1}.</p>
finding the position of a fraction in farey sequence
<p>For finding the position of a fraction in <a href="http://en.wikipedia.org/wiki/Farey_sequence" rel="nofollow">farey sequence</a>, i tried to implement the algorithm given here <a href="http://www.math.harvard.edu/~corina/publications/farey.pdf" rel="nofollow">http://www.math.harvard.edu/~corina/publications/farey.pdf</a>  under "<strong><em>initial algorithm</em></strong>" but i can't understand where i'm going wrong, i am not getting the correct answers . Could someone please point out my mistake.
eg. for order n = 7 and fractions 1/7 ,1/6 i get same answers.
Here's what i've tried for given degree(n), and a fraction a/b:</p>

<pre><code>sum=0;
int A[100000];
A[1]=a;

for(i=2;i&lt;=n;i++)
  A[i]=i*a-a;

for(i=2;i&lt;=n;i++)
{
  for(j=i+i;j&lt;=n;j+=i)
    A[j]-=A[i];
}

for(i=1;i&lt;=n;i++)
  sum+=A[i];

ans = sum/b;
</code></pre>

<p>Thanks.</p>