import java.math.BigInteger;

public class Euler192 {
    static long isqrt(long x) {
        long r = (long) Math.sqrt((double) x);
        while ((r + 1) <= x / (r + 1))
            r++;
        while (r > x / r)
            r--;
        return r;
    }

    public static void main(String[] args) {
        long dBound = 1000000000000L;
        BigInteger total = BigInteger.ZERO;
        for (long n = 2; n <= 100000; n++) {
            long a0 = isqrt(n);
            if (a0 * a0 == n)
                continue;
            long m = 0, d = 1, a = a0;
            BigInteger pp2 = BigInteger.ZERO, qp2 = BigInteger.ONE, pp1 = BigInteger.ONE, qp1 = BigInteger.ZERO;
            BigInteger bestQ = BigInteger.ONE;
            while (true) {
                BigInteger ba = BigInteger.valueOf(a);
                BigInteger p = ba.multiply(pp1).add(pp2);
                BigInteger q = ba.multiply(qp1).add(qp2);
                if (q.compareTo(BigInteger.valueOf(dBound)) > 0) {
                    bestQ = qp1;
                    BigInteger bdBound = BigInteger.valueOf(dBound);
                    if (bdBound.compareTo(qp1) > 0) {
                        BigInteger t = bdBound.subtract(qp2).divide(qp1);
                        if (t.signum() > 0) {
                            BigInteger qsc = t.multiply(qp1).add(qp2);
                            BigInteger rhs = BigInteger.valueOf(d)
                                    .multiply(BigInteger.TWO.multiply(t).multiply(qp1).add(qp2))
                                    .subtract(qp1.multiply(BigInteger.valueOf(m)));
                            if (rhs.signum() > 0) {
                                BigInteger upper = qp1.multiply(BigInteger.valueOf(a0 + 1));
                                if (rhs.compareTo(upper) > 0)
                                    bestQ = qsc;
                                else if (rhs.multiply(rhs)
                                        .compareTo(BigInteger.valueOf(n).multiply(qp1).multiply(qp1)) > 0)
                                    bestQ = qsc;
                            }
                        }
                    }
                    break;
                }
                pp2 = pp1;
                qp2 = qp1;
                pp1 = p;
                qp1 = q;
                long mn = d * a - m;
                long dn = (n - mn * mn) / d;
                long an = (a0 + mn) / dn;
                m = mn;
                d = dn;
                a = an;
            }
            total = total.add(bestQ);
        }
        System.out.println(total);
    }
}
