Пример #1
0
        static Frac[] restoreContinuedFraction(long[] arr)
        {
            /**
             * restore a double type number from an array of dominators of continued fraction
             **/
            int i = 0;

            Frac[] fracArray = new Frac[100];
            while (true)
            {
                if (arr[i] == -1)
                {
                    fracArray[i++] = new Frac(-1, 1);
                    if (i == 100)
                    {
                        break;
                    }
                    continue;
                }
                Frac cur = new Frac(0, 1);
                for (int j = i; j >= 0; --j)
                {
                    cur = cur.add(new Frac(arr[j], 1));
                    if (j == 0)
                    {
                        fracArray[i++] = cur;
                    }
                    else
                    {
                        cur = cur.inverse();
                    }
                }
            }
            return(fracArray);
        }
Пример #2
0
        static Frac getFrac(long[] a, int n)
        {
            Frac ans = new Frac(1, a[n]);

            for (int i = n - 1; i >= 1; i--)
            {
                ans = ans.add(new Frac(a[i], 1));
                ans = ans.inverse();
            }
            return(ans);
        }