OEIS · A395069 · Approved Apr 2026

The Card
Permutation
Sequence

How many steps does it take for a deck of n cards to return to its original state under a cyclic signed prefix-reversal shuffle? Discovered physically with a deck of cards by Fabio Longo.

2, 8, 9, 24, 50, 72, 28, 64, 162, 60, 121, 240, 234, 392, 75, 160, 204, 648, 228, 400, 294, 264, 529, 504, 200, 1352, 540, 504, 1682, 1800, 186, 384, 2178, 748, 1225, 324, 740, 1140, 1521, 2160, 3362, 336, 1204, 484, 540, 460, 1692, 2304, 1470, 5000, 2601, 624

The Shuffle

Start with n cards labeled 1 to n, all face up, in natural order. One full step consists of n sub-steps: in sub-step k (k = 1, 2, …, n), the top k cards are physically reversed as a block — their order is inverted and each card is flipped (face-up becomes face-down and vice versa). a(n) counts how many full steps are required to return to the original state.

Closed Form

a(n) = n × A002326(n)

Where A002326(n) is the multiplicative order of 2 modulo (2n+1) — the smallest k such that 2k ≡ 1 (mod 2n+1).
Formula contributed by Sean A. Irvine · Apr 20 2026

The deep reason: each full step acts as multiplication by 2 modulo (2n+1) on a cyclic encoding of the deck state. The deck returns to its initial configuration after exactly A002326(n) full cycles — each consisting of n sub-steps.

First 20 Terms

n A002326(n) a(n) = n × A002326(n)

Walkthrough: n = 3

Starting deck: [1↑, 2↑, 3↑]. Each card chip shows its label; rotated = face down. After 3 full steps (9 sub-steps total), the deck returns to its initial state.

Python Implementation

def a(n):
    # Each card: [id, face] where face 1=up, 0=down
    deck = [[i, 1] for i in range(n)]
    steps = 0
    while True:
        for k in range(1, n + 1):
            packet = deck[:k]
            packet.reverse()
            for card in packet:
                card[1] = 1 - card[1]
            deck = packet + deck[k:]
            steps += 1
            if all(deck[i][0] == i and deck[i][1] == 1
                   for i in range(n)):
                return steps

print([a(n) for n in range(1, 21)])
# Verified manually and computationally up to n=20

Sequence Info

OEIS ID
Author
Fabio Longo, Apr 10 2026
Offset
1, 1
Keywords
nonn, new
Formula by
Sean A. Irvine, Apr 20 2026
Cross-refs
Status
✓ Approved