Okay. Here is some code to determine the number of digits in the
period of repetition of the decimal expansion of 1/n, where n > 0:

int period(int n);
{
    int i=1,j=0;
    while( n % 2 == 0 )
        n /= 2;
    while( n % 5 == 0 )
        n /= 5;
    do
    {
        i = (10 * i) % n;
        ++j;
    } while( i > 1 );
    return j;
}

Given the relatively prime pair of integers m and n, once you know the
number of digits in a repeat of 1/n, you can easily find the repeating
digits in the decimal expansion of the fraction m/n.

Dave

On Jul 2, 7:42 am, jalaj jaiswal <[email protected]> wrote:
> hmm..... :-o
>
>
>
>
>
> On Fri, Jul 2, 2010 at 5:57 PM, Dave <[email protected]> wrote:
> > Yes. With a period of 16:
> > 1/17 = 0.0588235294117647 0588235294117647 0588235294117647 ...
>
> > Dave
>
> > On Jul 2, 5:22 am, jalaj jaiswal <[email protected]> wrote:
> > > @dave
> > > is 1/17 recurring...??
> > > @abhirup
> > > now convert float to string ..only part after decimal
>
> > > now let the string be .346346346.....
> > > take an auxilarry array a[0--9]..initialize it to zero
> > > as you encounter update inceremnt a[s[i]-48]
> > > wheneva you element in tha array becomes 2
> > > store i-1
> > > now from 0 to i-1 is the desired answer
>
> > > On Fri, Jul 2, 2010 at 3:45 PM, Abhirup Ghosh <[email protected]>
> > wrote:
> > > > Can you please elaborate on the solution you have with auxiliary array?
>
> > > > On Fri, Jul 2, 2010 at 3:53 AM, jalaj jaiswal <
> > [email protected]>
> > > > wrote:
>
> > > > > we are given with  Numerator and Denominator. After division we might
> > get
> > > > a
> > > > > recurring decimal points float as the answer.
> > > > > For example 23.34563456 ...
> > > > > return 3456 i.e the recurring part
>
> > > > > i did it by converting the decimal part into string(itoa).. then a
> > scan
> > > > to
> > > > > find the first repeated character ...then outputting the string upto
> > that
> > > > > location of first character-1
> > > > >  i found first repeated character using an auxilarry array[0..9]..
> > > > > total 3 scans.. O(n)
>
> > > > > any better solutions please ??
> > > > > --
>
> > > > > With Regards,
> > > > > Jalaj Jaiswal
> > > > > +919026283397
> > > > > B.TECH IT
> > > > > IIIT ALLAHABAD
>
> > > > > --
> > > >  > You received this message because you are subscribed to the Google
> > > > Groups
> > > > > "Algorithm Geeks" group.
> > > > > To post to this group, send email to [email protected].
> > > > > To unsubscribe from this group, send email to
> > > > > [email protected]<algogeeks%2bunsubscr...@googlegroups­.com>
> > <algogeeks%2bunsubscr...@googlegroups­.com>
> > > > .
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/algogeeks?hl=en.
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "Algorithm Geeks" group.
> > > > To post to this group, send email to [email protected].
> > > > To unsubscribe from this group, send email to
> > > > [email protected]<algogeeks%2bunsubscr...@googlegroups­.com>
> > <algogeeks%2bunsubscr...@googlegroups­.com>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/algogeeks?hl=en.
>
> > > --
> > > With Regards,
> > > Jalaj Jaiswal
> > > +919026283397
> > > B.TECH IT
> > > IIIT ALLAHABAD- Hide quoted text -
>
> > > - Show quoted text -
>
> > --
> >  You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<algogeeks%2bunsubscr...@googlegroups­.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> With Regards,
> Jalaj Jaiswal
> +919026283397
> B.TECH IT
> IIIT ALLAHABAD- Hide quoted text -
>
> - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to