func (c Chain) Op(k int) (Op, error) {
	ops := c.Ops(k)
	if len(ops) == 0 {
		return Op{}, fmt.Errorf("position %d is not the sum of previous entries", k)
	}
	return ops[0], nil
}
Op returns an Op that produces the kth position.
package addchain
import (
	"errors"
	"fmt"
	"math/big"
	"github.com/mmcloughlin/addchain/internal/bigint"
	"github.com/mmcloughlin/addchain/internal/bigints"
)
type Chain []*big.Int
func New() Chain {
	return Chain{big.NewInt(1)}
}
func Int64s(xs ...int64) Chain {
	return Chain(bigints.Int64s(xs...))
}
func (c Chain) Clone() Chain {
	return bigints.Clone(c)
}
func (c *Chain) AppendClone(x *big.Int) {
	*c = append(*c, bigint.Clone(x))
}
func (c Chain) End() *big.Int {
	return c[len(c)-1]
}
func (c Chain) Ops(k int) []Op {
	ops := []Op{}
	s := new(big.Int)
	if c[:k].IsAscending() {
		for l, r := 0, k-1; l <= r; {
			s.Add(c[l], c[r])
			cmp := s.Cmp(c[k])
			if cmp == 0 {
				ops = append(ops, Op{l, r})
			}
			if cmp <= 0 {
				l++
			} else {
				r--
			}
		}
		return ops
	}
	for i := 0; i < k; i++ {
		for j := i; j < k; j++ {
			s.Add(c[i], c[j])
			if s.Cmp(c[k]) == 0 {
				ops = append(ops, Op{i, j})
			}
		}
	}
	return ops
}