public static void main(String[] args) {

//        System.out.println("#---------");
        final int max = 20000;
        final HashMap<Long, Integer> map = new HashMap<Long, Integer>(2 * max);
        final ArrayList<Long> list = new ArrayList<Long>(max);
        for (int n = 1; n <= max; n++) {
            final long pn = getPentagonal(n);
//            System.out.println(n + "\t" + pn);
            map.put(pn, n);
            list.add(pn);
        }
//        System.out.println("#---------");
        int cnt = 0;
        long dmin = Long.MAX_VALUE;
        for (int i = 0; i < max; i++) {
            final long pni = list.get(i);
            for (int j = i + 1; j < max; j++) {
                if (++cnt % 10000000 == 0) {
                    System.out.println("# processed " + cnt + " pairs so far.");
                }
                final long pnj = list.get(j);
                final long psum = pni + pnj;
                if (map.containsKey(psum)) {
                    final long pdiff = pnj - pni;
                    if (map.containsKey(pdiff)) {
                        System.out.println("# sum and diff are Pentagonal; "+i + "\t" + j + "\t" + pni + "\t" + pnj);
                        final long d = java.lang.Math.abs(pni - pnj);
                        if (d < dmin) {
                            System.out.println("# new d_min; "+i + "\t" + j + "\t" + pni + "\t" + pnj + "\t" + d);
                            dmin = d;
                        }
                    }
                }
            }
        }
        System.out.println("# dmin = " + dmin);
    }