Exemplo n.º 1
0
        public int Solve()
        {
            BigInteger max = -1;
            int result = -1;

            for (int i = 1; i <= limit; i++) {
                int root = (int)Math.Sqrt(i);
                if (root * root != i) {
                    ContinuedFraction fraction = new ContinuedFraction(i);
                    bool found = false;
                    BigInteger[] next = new BigInteger[] { 0 };
                    while (!found) {
                        next = fraction.GetNext();
                        if(next[0] * next[0] - i * next[1] * next[1] == 1) {
                            found = true;
                        }
                    }

                    if(max < next[0]) {
                        max = next[0];
                        result = i;
                    }
                }
            }
            return result;
        }
Exemplo n.º 2
0
        public int Solve()
        {
            int count = 0;

            for (int i = 1; i <= limit; i++) {
                try {
                    ContinuedFraction squareRoot = new ContinuedFraction(i);
                    if(squareRoot.GetPeriod()%2 == 1) {
                        count++;
                    }
                }
                catch(Exception e) {
                }
            }

            return count;
        }