281. Java 5,11628字节,A000947
// package oeis_challenge;
import java.util.*;
import java.lang.*;
class Main {
//  static void assert(boolean cond) {
//      if (!cond)
//          throw new Error("Assertion failed!");
//  }
    /* Use the formula a(n) = A000063(n + 2) - A000936(n).
    It's unfair that I use the formula of "number of free polyenoid with n
    nodes and symmetry point group C_{2v}" (formula listed in A000063)
    without understanding why it's true...
    */
    static int catalan(int x) {
        int ans = 1;
        for (int i = 1; i <= x; ++i)
            ans = ans * (2*x+1-i) / i;
        return ans / -~x;
    }
    static int A63(int n) {
        int ans = catalan(n/2 - 1);
        if (n%4 == 0) ans -= catalan(n/4 - 1);
        if (n%6 == 0) ans -= catalan(n/6 - 1);
        return ans;
    }
    static class Point implements Comparable<Point> {
        final int x, y;
        Point(int _x, int _y) {
            x = _x; y = _y;
        }
        /// @return true if this is a point, false otherwise (this is a vector)
        public boolean isPoint() {
            return (x + y) % 3 != 0;
        }
        /// Translate this point by a vector.
        public Point add(Point p) {
            assert(this.isPoint() && ! p.isPoint());
            return new Point(x + p.x, y + p.y);
        }
        /// Reflect this point along x-axis.
        public Point reflectX() {
            return new Point(x - y, -y);
        }
        /// Rotate this point 60 degrees counter-clockwise.
        public Point rot60() {
            return new Point(x - y, x);
        }
        @Override
        public boolean equals(Object o) {
            if (!(o instanceof Point)) return false;
            Point p = (Point) o;
            return x == p.x && y == p.y;
        }
        @Override
        public int hashCode() {
            return 21521 * (3491 + x) + y;
        }
        public String toString() {
            // return String.format("(%d, %d)", x, y);
            return String.format("setxy %d %d", x * 50 - y * 25, y * 40);
        }
        public int compareTo(Point p) {
            int a = Integer.valueOf(x).compareTo(p.x);
            if (a != 0) return a;
            return Integer.valueOf(y).compareTo(p.y);
        }
        /// Helper class.
        static interface Predicate {
            abstract boolean test(Point p);
        }
        static abstract class UnaryFunction {
            abstract Point apply(Point p);
        }
    }
    static class Edge implements Comparable<Edge> {
        final Point a, b; // guarantee a < b
        Edge(Point x, Point y) {
            assert x != y;
            if (x.compareTo(y) > 0) { // y < x
                a = y; b = x;
            } else {
                a = x; b = y;
            }
        }
        public int compareTo(Edge e) {
            int x = a.compareTo(e.a);
            if (x != 0) return x;
            return b.compareTo(e.b);
        }
    }
    /// A graph consists of multiple {@code Point}s.
    static class Graph {
        private HashMap<Point, Point> points;
        public Graph() {
            points = new HashMap<Point, Point>();
        }
        public Graph(Graph g) {
            points = new HashMap<Point, Point>(g.points);
        }
        public void add(Point p, Point root) {
            assert(p.isPoint());
            assert(root.isPoint());
            assert(p == root || points.containsKey(root));
            points.put(p, root);
        }
        public Graph map(Point.UnaryFunction fn) {
            Graph result = new Graph();
            for (Map.Entry<Point, Point> pq : points.entrySet()) {
                Point p = pq.getKey(), q = pq.getValue();
                assert(p.isPoint()) : p;
                assert(q.isPoint()) : q;
                p = fn.apply(p); assert(p.isPoint()) : p;
                q = fn.apply(q); assert(q.isPoint()) : q;
                result.points.put(p, q);
            }
            return result;
        }
        public Graph reflectX() {
            return this.map(new Point.UnaryFunction() {
                public Point apply(Point p) {
                    return p.reflectX();
                }
            });
        }
        public Graph rot60() {
            return this.map(new Point.UnaryFunction() {
                public Point apply(Point p) {
                    return p.rot60();
                }
            });
        }
        @Override
        public boolean equals(Object o) {
            if (o == null) return false;
            if (o.getClass() != getClass()) return false;
            Graph g = (Graph) o;
            return points.equals(g.points);
        }
        @Override
        public int hashCode() {
            return points.hashCode();
        }
        Graph[] expand(Point.Predicate fn) {
            List<Graph> result = new ArrayList<Graph>();
            for (Point p : points.keySet()) {
                int[] deltaX = new int[] { -1, 0, 1, 1,  0, -1};
                int[] deltaY = new int[] {  0, 1, 1, 0, -1, -1};
                for (int i = 6; i --> 0;) {
                    Point p1 = new Point(p.x + deltaX[i], p.y + deltaY[i]);
                    if (points.containsKey(p1) || !fn.test(p1)
                        || !p1.isPoint()) continue;
                    Graph g = new Graph(this);
                    g.add(p1, p);
                    result.add(g);
                }
            }
            return result.toArray(new Graph[0]);
        }
        public static Graph[] expand(Graph[] graphs, Point.Predicate fn) {
            Set<Graph> result = new HashSet<Graph>();
            for (Graph g0 : graphs) {
                Graph[] g = g0.expand(fn);
                for (Graph g1 : g) {
                    if (result.contains(g1)) continue;
                    result.add(g1);
                }
            }
            return result.toArray(new Graph[0]);
        }
        private Edge[] edges() {
            List<Edge> result = new ArrayList<Edge>();
            for (Map.Entry<Point, Point> pq : points.entrySet()) {
                Point p = pq.getKey(), q = pq.getValue();
                if (p.equals(q)) continue;
                result.add(new Edge(p, q));
            }
            return result.toArray(new Edge[0]);
        }
        /**
         * Check if two graphs are isomorphic... under translation.
         * @return {@code true} if {@code this} is isomorphic
         * under translation, {@code false} otherwise.
         */
        public boolean isomorphic(Graph g) {
            if (points.size() != g.points.size()) return false;
            Edge[] a = this.edges();
            Edge[] b = g.edges();
            Arrays.sort(a);
            Arrays.sort(b);
            // for (Edge e : b)
                // System.err.println(e.a + " - " + e.b);
            // System.err.println("------- >><< ");
            assert (a.length > 0);
            assert (a.length == b.length);
            int a_bx = a[0].a.x - b[0].a.x, a_by = a[0].a.y - b[0].a.y;
            for (int i = 0; i < a.length; ++i) {
                if (a_bx != a[i].a.x - b[i].a.x || 
                    a_by != a[i].a.y - b[i].a.y) return false;
                if (a_bx != a[i].b.x - b[i].b.x || 
                    a_by != a[i].b.y - b[i].b.y) return false;
            }
            return true;
        }
        // C_{2v}.
        public boolean correctSymmetry() {
            Graph[] graphs = new Graph[6];
            graphs[0] = this.reflectX();
            for (int i = 1; i < 6; ++i) graphs[i] = graphs[i-1].rot60();
            assert(graphs[5].rot60().isomorphic(graphs[0]));
            int count = 0;
            for (Graph g : graphs) {
                if (this.isomorphic(g)) ++count;
                // if (count >= 2) {
                    // return false;
                // }
            }
            // if (count > 1) System.err.format("too much: %d%n", count);
            assert(count > 0);
            return count == 1; // which is, basically, true
        }
        public void reflectSelfType2() {
            Graph g = this.map(new Point.UnaryFunction() {
                public Point apply(Point p) {
                    return new Point(p.y - p.x, p.y);
                }
            });
            Point p = new Point(1, 1);
            assert (p.equals(points.get(p)));
            points.putAll(g.points);
            assert (p.equals(points.get(p)));
            Point q = new Point(0, 1);
            assert (q.equals(points.get(q)));
            points.put(p, q);
        }
        public void reflectSelfX() {
            Graph g = this.reflectX();
            points.putAll(g.points); // duplicates doesn't matter
        }
    }
    static int A936(int n) {
        // if (true) return (new int[]{0, 0, 0, 1, 1, 2, 4, 4, 12, 10, 29, 27, 88, 76, 247, 217, 722, 638, 2134, 1901, 6413})[n];
        // some unreachable codes here for testing.
        int ans = 0;
        if (n % 2 == 0) { // reflection type 2. (through line 2x == y)
            Graph[] graphs = new Graph[1];
            graphs[0] = new Graph();
            Point p = new Point(1, 1);
            graphs[0].add(p, p);
            for (int i = n / 2 - 1; i --> 0;)
                graphs = Graph.expand(graphs, new Point.Predicate() {
                    public boolean test(Point p) {
                        return 2*p.x > p.y;
                    }
                });
            int count = 0;
            for (Graph g : graphs) {
                g.reflectSelfType2();
                if (g.correctSymmetry()) {
                    ++count;
                    // for (Edge e : g.edges())
                        // System.err.println(e.a + " - " + e.b);
                    // System.err.println("------*");
                    }
                // else System.err.println("Failed");
            }
            assert (count%2 == 0);
            // System.err.println("A936(" + n + ") count = " + count + " -> " + (count/2));
            ans += count / 2;
        }
        // Reflection type 1. (reflectX)
        Graph[] graphs = new Graph[1];
        graphs[0] = new Graph();
        Point p = new Point(1, 0);
        graphs[0].add(p, p);
        if (n % 2 == 0) graphs[0].add(new Point(2, 0), p);
        for (int i = (n-1) / 2; i --> 0;)
            graphs = Graph.expand(graphs, new Point.Predicate() {
                public boolean test(Point p) {
                    return p.y > 0;
                }
            });
        int count = 0;
        for (Graph g : graphs) {
            g.reflectSelfX();
            if (g.correctSymmetry()) {
                ++count;
                // for (Edge e : g.edges())
                    // System.err.printf(
                // "pu %s pd %s\n"
                // // "%s - %s%n"
                // , e.a, e.b);
                // System.err.println("-------/");
            }
            // else System.err.println("Failed");
        }
        if(n % 2 == 0) {
            assert(count % 2 == 0);
            count /= 2;
        }
        ans += count;
        // System.err.println("A936(" + n + ") = " + ans);
        return ans;
    }
    public static void main(String[] args) {
        // Probably
        if (! "1.5.0_22".equals(System.getProperty("java.version"))) {
            System.err.println("Warning: Java version is not 1.5.0_22");
        }
        // A936(6);
        for (int i = 0; i < 20; ++i)
            System.out.println(i + " | " + (A63(i+9) - A936(i+7)));
        //A936(i+2);
    }
}
在线尝试!
边注:
- 已在Java 5上进行了本地测试(这样不会显示警告-请参见“ TIO调试”选项卡)
- 别。曾经 采用。Java。1.一般而言,它比Java更冗长。
- 这可能会中断链。 
- 间隔(7天48分钟)不超过此答案产生的间隔,即比上一个答案晚7天零1 25分钟。
- 大字节数的新记录!因为我(错误地?)使用空格而不是制表符,所以字节数超出了必要。在我的机器上是9550字节。(在撰写此修订本时)
- 下一个序列。
- 当前形式的代码仅显示序列的前20个字词。但是它很容易改变,因此,它会首先打印1000个项目(通过将改变20在for (int i = 0; i < 20; ++i)向1000)
好极了!这可以计算出比OEIS页面上列出的更多的术语!(这是我第一次需要挑战,我需要使用Java),除非OEIS在某处有更多术语...
快速说明
序列说明的说明。
该序列要求对称组为C 2v的自由非平面多烯类化合物的数量,其中:
- polyenoid :(多烯碳氢化合物的数学模型)可嵌入六边形格子中的树(或在退化情况下为单个顶点)。
例如,考虑树木
      O                O           O      O       (3)
      |                 \         /        \
      |                  \       /          \
O --- O --- O             O --- O            O --- O
      |                                             \
      |                    (2)                       \
 (1)  O                                               O
第一个不能嵌入六边形格子,而第二个可以。该特定的嵌入被认为与第三棵树不同。
(2)和(3)上面的树是平面的。但是,这是非平面的:
   O---O O
  /       \
 /         \
O           O
 \         /
  \       /
   O --- O
(有7个顶点和6个边)
- 游离多烯体:可以通过旋转和反射获得的一种多烯体的变体计为一个。

- C 2v组:仅在具有两个垂直反射平面且没有更多反射平面的情况下才对多烯类进行计数。
例如,只有两个顶点的多面体
O --- O
具有3个反射平面:水平的-,垂直的|和与计算机屏幕平行的一个■。这太多了。
另一方面,这个
O --- O
       \
        \
         O
有2个反射平面:/和■。
方法说明
现在,该方法涉及如何实际计算数字。
首先,我认为公式a(n) = A000063(n + 2) - A000936(n)(在OEIS页面上列出)是理所当然的。我没有阅读论文中的解释。
[TODO修复此部分]
当然,平面计数要比非平面计数容易。这也是论文的目的。
  几何平面的多烯类化合物(没有重叠的顶点)由计算机程序枚举。因此,几何上非平面的多烯类化合物的数目变得可访问。
所以...该程序计算平面多面体的数量,然后从总数中减去。
由于树无论如何都是平面的,因此显然具有■反射平面。因此,条件归结为“在2D表示中具有反射轴的树的数量”。
天真的方法是生成带有n节点的所有树,并检查正确的对称性。但是,因为我们只想找到具有反射轴的树的数量,所以我们可以只在一个半轴上生成所有可能的半树,并通过轴镜像它们,然后检查正确的对称性。此外,由于生成的多烯类化合物是(平面)树,因此它必须恰好接触一次反射轴。
该函数public static Graph[] expand(Graph[] graphs, Point.Predicate fn)采用一个图形数组,每个图形都有n节点,并输出一个图形数组,每个图形都有彼此n+1不相等的节点(在转换中)-这样添加的节点必须满足谓词fn。
考虑两个可能的反射轴:一个穿过顶点并与边缘重合(x = 0),另一个是边缘的垂直平分线(2x = y)。无论如何,我们只能采用其中之一,因为生成的图是同构的。

因此,对于第一个轴x = 0,我们从基础图开始,该基础图由一个节点(1, 0)(如果n是奇数)或两个节点之间有一条边(1, 0) - (2, 0)(如果n是偶数)组成,然后展开这样的节点y > 0。这是通过程序的“反射类型1”部分完成的,然后对于每个生成的图形,通过X轴x = 0(g.reflectSelfX())反射(镜像)自身,然后检查其是否具有正确的对称性。
但是,请注意,如果n被2整除,则通过这种方式我们对每个图形计数了两次,因为我们还通过轴生成了其镜像2x = y + 3。

(注意2个橙色的)
对于轴类似2x = y,如果(且仅当)n是偶数,我们从该点开始(1, 1),生成,使2*x > y,并将它们反射到2x = y轴(g.reflectSelfType2())上,(1, 0)与连接(1, 1),然后检查它们是否具有正确的对称性。记住也要除以2。