Problem 486

Palindrome-containing Strings — D(10^18) via period-6 free counts + CRT.

Answer11408450515
Output11408450515
StatusPASS
Native helperno
Runtime30 ms
Peak memory1104 KB
Time complexityO(n^2) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n^2)
Space complexityO(1)O(1)
ApproachFlow solutionBrute-force or constructive search
VerdictOptimal

Flow source

# Project Euler 486
# Palindrome-containing Strings — D(10^18) via period-6 free counts + CRT.

function modinv(a0: i64, m: i64) -> i64 {
    let mut a: i64 = a0 % m
    let mut b: i64 = m
    let mut x0: i64 = 1
    let mut x1: i64 = 0
    while b != 0 {
        let q: i64 = a / b
        let t: i64 = a - q * b
        a = b
        b = t
        let tx: i64 = x0 - q * x1
        x0 = x1
        x1 = tx
    }
    if x0 < 0 { x0 = x0 + m }
    return x0
}

function modpow(base0: i64, exp0: i64, mod: i64) -> i64 {
    let mut r: i64 = 1
    let mut b: i64 = base0 % mod
    let mut e: i64 = exp0
    while e > 0 {
        if e % 2 == 1 {
            r = (r * b) % mod
        }
        b = (b * b) % mod
        e = e / 2
    }
    return r
}

function main() -> i32 {
    let m: i64 = 87654321
    let L: i64 = 1000000000000000000
    let B6: i64 = 85
    let o64: i64 = 1216562
    let period_q: i64 = m * o64
    let inv200: i64 = modinv(200, m)
    let inv_o: i64 = modinv(o64, m)
    let PREFIX: array<i64, 6> = [0, 32, 64, 96, 130, 166]
    let pow2: array<i64, 6> = [0, 0, 0, 0, 0, 0]
    let C: array<i64, 6> = [0, 0, 0, 0, 0, 0]
    let Rlist: array<i64, 6> = [0, 0, 0, 0, 0, 0]
    let mut base: i64 = 0
    let mut r: i64 = 0
    while r < 6 {
        pow2[r] = modpow(2, r + 7, m)
        C[r] = (1 + B6 + PREFIX[r]) % m
        let qmax: i64 = (L - r - 6) / 6
        let N: i64 = qmax + 1
        let Q: i64 = N / period_q
        base = base + Q * o64
        Rlist[r] = N - Q * period_q
        r = r + 1
    }
    let mut extra: i64 = 0
    let mut pow64: i64 = 1
    let mut k: i64 = 0
    while k < o64 {
        r = 0
        while r < 6 {
            let Lval: i64 = (pow2[r] * pow64) % m
            let mut q0: i64 = ((Lval - C[r]) % m + m) % m
            q0 = (q0 * inv200) % m
            let mut diff: i64 = q0 - k
            if diff < 0 { diff = diff + m }
            let t: i64 = (diff * inv_o) % m
            let q_res: i64 = k + o64 * t
            if q_res < Rlist[r] {
                extra = extra + 1
            }
            r = r + 1
        }
        pow64 = (pow64 * 64) % m
        k = k + 1
    }
    # F5(5)=8, 8 % m != 0, so no add5
    printf("%lld\n", base + extra)
    return 0
}

Generated C

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
    while (flow_temp_head) {
        flow_temp_node* n = flow_temp_head;
        flow_temp_head = n->next;
        free(n);
    }
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
    flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
    if (!node) return NULL;
    node->next = flow_temp_head;
    flow_temp_head = node;
    if (!flow_temp_atexit_set) {
        flow_temp_atexit_set = 1;
        atexit(flow_temp_free_all);
    }
    return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
    size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
    char* r = (char*)flow_temp_alloc(la + lb + 1);
    if (!r) return NULL;
    if (la) memcpy(r, a, la);
    if (lb) memcpy(r + la, b, lb);
    r[la + lb] = '\0';
    return r;
}

#define __flow_in_arr(arr, val) __extension__ ({ \
    int _found = 0; \
    size_t _n = sizeof(arr)/sizeof((arr)[0]); \
    for (size_t _i = 0; _i < _n; _i++) { \
        if ((arr)[_i] == (val)) { _found = 1; break; } \
    } _found; })

/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
    fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
    abort();
#if defined(__GNUC__) || defined(__clang__)
    __builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")

#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif

#include <math.h>

void* _ui_state = NULL;

static inline float i32_to_f32(int32_t v) { return (float)v; }

/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }

int64_t modinv_i64_i64(int64_t a0, int64_t m);
int64_t modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod);
int32_t main(void);

int64_t modinv_i64_i64(int64_t a0, int64_t m) {
    int64_t a = FLOW_CHECKED_MOD((a0), (m));
    int64_t b = m;
    int64_t x0 = 1;
    int64_t x1 = 0;
    while (b != 0) {
        int64_t q = FLOW_CHECKED_DIV((a), (b));
        int64_t t = (a - (q * b));
        a = b;
        b = t;
        int64_t tx = (x0 - (q * x1));
        x0 = x1;
        x1 = tx;
    }
    if (x0 < 0) {
        x0 = (x0 + m);
    }
    return x0;
}

int64_t modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod) {
    int64_t r = 1;
    int64_t b = FLOW_CHECKED_MOD((base0), (mod));
    int64_t e = exp0;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            r = FLOW_CHECKED_MOD(((r * b)), (mod));
        }
        b = FLOW_CHECKED_MOD(((b * b)), (mod));
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return r;
}

int32_t main(void) {
    int64_t m = 87654321;
    int64_t L = 1000000000000000000;
    int64_t B6 = 85;
    int64_t o64 = 1216562;
    int64_t period_q = (m * o64);
    int64_t inv200 = modinv_i64_i64(200, m);
    int64_t inv_o = modinv_i64_i64(o64, m);
    int64_t PREFIX[6] = { 0, 32, 64, 96, 130, 166 };
    int64_t pow2[6] = { 0, 0, 0, 0, 0, 0 };
    int64_t C[6] = { 0, 0, 0, 0, 0, 0 };
    int64_t Rlist[6] = { 0, 0, 0, 0, 0, 0 };
    int64_t base = 0;
    int64_t r = 0;
    while (r < 6) {
        pow2[r] = modpow_i64_i64_i64(2, (r + 7), m);
        C[r] = FLOW_CHECKED_MOD((((1 + B6) + (((unsigned)(r) < 6) ? PREFIX[r] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(r), 6), flow_fault_handler("array index out of bounds"), PREFIX[0])))), (m));
        int64_t qmax = FLOW_CHECKED_DIV((((L - r) - 6)), (6));
        int64_t N = (qmax + 1);
        int64_t Q = FLOW_CHECKED_DIV((N), (period_q));
        base = (base + (Q * o64));
        Rlist[r] = (N - (Q * period_q));
        r = (r + 1);
    }
    int64_t extra = 0;
    int64_t pow64 = 1;
    int64_t k = 0;
    while (k < o64) {
        r = 0;
        while (r < 6) {
            int64_t Lval = FLOW_CHECKED_MOD((((((unsigned)(r) < 6) ? pow2[r] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(r), 6), flow_fault_handler("array index out of bounds"), pow2[0])) * pow64)), (m));
            int64_t q0 = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((Lval - (((unsigned)(r) < 6) ? C[r] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(r), 6), flow_fault_handler("array index out of bounds"), C[0])))), (m)) + m)), (m));
            q0 = FLOW_CHECKED_MOD(((q0 * inv200)), (m));
            int64_t diff = (q0 - k);
            if (diff < 0) {
                diff = (diff + m);
            }
            int64_t t = FLOW_CHECKED_MOD(((diff * inv_o)), (m));
            int64_t q_res = (k + (o64 * t));
            if (q_res < (((unsigned)(r) < 6) ? Rlist[r] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(r), 6), flow_fault_handler("array index out of bounds"), Rlist[0]))) {
                extra = (extra + 1);
            }
            r = (r + 1);
        }
        pow64 = FLOW_CHECKED_MOD(((pow64 * 64)), (m));
        k = (k + 1);
    }
    printf("%lld\n", (base + extra));
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func @modinv(%arg0: i64, %arg1: i64) -> i64 {
    %0 = arith.remsi %arg0, %arg1 : i64
    %1 = llvm.mlir.constant(1 : i64) : i64
    %2 = llvm.alloca %1 x i64 : (i64) -> !llvm.ptr
    llvm.store %0, %2 : i64, !llvm.ptr
    %3 = llvm.mlir.constant(1 : i64) : i64
    %4 = llvm.alloca %3 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %4 : i64, !llvm.ptr
    %5 = arith.constant 1 : i32
    %6 = arith.extsi %5 : i32 to i64
    %7 = llvm.mlir.constant(1 : i64) : i64
    %8 = llvm.alloca %7 x i64 : (i64) -> !llvm.ptr
    llvm.store %6, %8 : i64, !llvm.ptr
    %9 = arith.constant 0 : i32
    %10 = arith.extsi %9 : i32 to i64
    %11 = llvm.mlir.constant(1 : i64) : i64
    %12 = llvm.alloca %11 x i64 : (i64) -> !llvm.ptr
    llvm.store %10, %12 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %13 = llvm.load %4 : !llvm.ptr -> i64
    %14 = arith.constant 0 : i32
    %16 = arith.extsi %14 : i32 to i64
    %15 = arith.cmpi ne, %13, %16 : i64
    cf.cond_br %15, ^bb1, ^bb2
    ^bb1:
      %17 = llvm.load %2 : !llvm.ptr -> i64
      %18 = llvm.load %4 : !llvm.ptr -> i64
      %19 = arith.divsi %17, %18 : i64
      %20 = llvm.load %2 : !llvm.ptr -> i64
      %21 = llvm.load %4 : !llvm.ptr -> i64
      %22 = arith.muli %19, %21 : i64
      %23 = arith.subi %20, %22 : i64
      %24 = llvm.load %4 : !llvm.ptr -> i64
      llvm.store %24, %2 : i64, !llvm.ptr
      llvm.store %23, %4 : i64, !llvm.ptr
      %25 = llvm.load %8 : !llvm.ptr -> i64
      %26 = llvm.load %12 : !llvm.ptr -> i64
      %27 = arith.muli %19, %26 : i64
      %28 = arith.subi %25, %27 : i64
      %29 = llvm.load %12 : !llvm.ptr -> i64
      llvm.store %29, %8 : i64, !llvm.ptr
      llvm.store %28, %12 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %30 = llvm.load %8 : !llvm.ptr -> i64
    %31 = arith.constant 0 : i32
    %33 = arith.extsi %31 : i32 to i64
    %32 = arith.cmpi slt, %30, %33 : i64
    cf.cond_br %32, ^bb3, ^bb4
    ^bb3:
      %34 = llvm.load %8 : !llvm.ptr -> i64
      %35 = arith.addi %34, %arg1 : i64
      llvm.store %35, %8 : i64, !llvm.ptr
      cf.br ^bb5
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %36 = llvm.load %8 : !llvm.ptr -> i64
    func.return %36 : i64
  }
  func.func @modpow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %37 = arith.constant 1 : i32
    %38 = arith.extsi %37 : i32 to i64
    %39 = llvm.mlir.constant(1 : i64) : i64
    %40 = llvm.alloca %39 x i64 : (i64) -> !llvm.ptr
    llvm.store %38, %40 : i64, !llvm.ptr
    %41 = arith.remsi %arg0, %arg2 : i64
    %42 = llvm.mlir.constant(1 : i64) : i64
    %43 = llvm.alloca %42 x i64 : (i64) -> !llvm.ptr
    llvm.store %41, %43 : i64, !llvm.ptr
    %44 = llvm.mlir.constant(1 : i64) : i64
    %45 = llvm.alloca %44 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %45 : i64, !llvm.ptr
    cf.br ^bb6
    ^bb6:
    %46 = llvm.load %45 : !llvm.ptr -> i64
    %47 = arith.constant 0 : i32
    %49 = arith.extsi %47 : i32 to i64
    %48 = arith.cmpi sgt, %46, %49 : i64
    cf.cond_br %48, ^bb7, ^bb8
    ^bb7:
      %50 = llvm.load %45 : !llvm.ptr -> i64
      %51 = arith.constant 2 : i32
      %53 = arith.extsi %51 : i32 to i64
      %52 = arith.remsi %50, %53 : i64
      %54 = arith.constant 1 : i32
      %56 = arith.extsi %54 : i32 to i64
      %55 = arith.cmpi eq, %52, %56 : i64
      cf.cond_br %55, ^bb9, ^bb10
      ^bb9:
        %57 = llvm.load %40 : !llvm.ptr -> i64
        %58 = llvm.load %43 : !llvm.ptr -> i64
        %59 = arith.muli %57, %58 : i64
        %60 = arith.remsi %59, %arg2 : i64
        llvm.store %60, %40 : i64, !llvm.ptr
        cf.br ^bb11
      ^bb10:
        cf.br ^bb11
      ^bb11:
      %61 = llvm.load %43 : !llvm.ptr -> i64
      %62 = llvm.load %43 : !llvm.ptr -> i64
      %63 = arith.muli %61, %62 : i64
      %64 = arith.remsi %63, %arg2 : i64
      llvm.store %64, %43 : i64, !llvm.ptr
      %65 = llvm.load %45 : !llvm.ptr -> i64
      %66 = arith.constant 2 : i32
      %68 = arith.extsi %66 : i32 to i64
      %67 = arith.divsi %65, %68 : i64
      llvm.store %67, %45 : i64, !llvm.ptr
      cf.br ^bb6
    ^bb8:
    %69 = llvm.load %40 : !llvm.ptr -> i64
    func.return %69 : i64
  }
  func.func @main() -> i32 {
    %70 = arith.constant 87654321 : i32
    %71 = arith.extsi %70 : i32 to i64
    %72 = arith.constant 999999995705032704 : i32
    %73 = arith.extsi %72 : i32 to i64
    %74 = arith.constant 85 : i32
    %75 = arith.extsi %74 : i32 to i64
    %76 = arith.constant 1216562 : i32
    %77 = arith.extsi %76 : i32 to i64
    %78 = arith.muli %71, %77 : i64
    %80 = arith.constant 200 : i32
    %81 = arith.extsi %80 : i32 to i64
    %79 = func.call @modinv(%81, %71) : (i64, i64) -> i64
    %82 = func.call @modinv(%77, %71) : (i64, i64) -> i64
    %84 = arith.constant 0 : i32
    %85 = arith.constant 32 : i32
    %86 = arith.constant 64 : i32
    %87 = arith.constant 96 : i32
    %88 = arith.constant 130 : i32
    %89 = arith.constant 166 : i32
    %90 = llvm.mlir.constant(1 : i64) : i64
    %91 = llvm.alloca %90 x !llvm.array<6 x i64> : (i64) -> !llvm.ptr
    %92 = llvm.mlir.zero : !llvm.array<6 x i64>
    llvm.store %92, %91 : !llvm.array<6 x i64>, !llvm.ptr
    %93 = arith.extsi %84 : i32 to i64
    %94 = arith.extsi %85 : i32 to i64
    %95 = arith.extsi %86 : i32 to i64
    %96 = arith.extsi %87 : i32 to i64
    %97 = arith.extsi %88 : i32 to i64
    %98 = arith.extsi %89 : i32 to i64
    %99 = llvm.mlir.constant(0 : i64) : i64
    %100 = llvm.getelementptr %91[0, %99] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %93, %100 : i64, !llvm.ptr
    %101 = llvm.mlir.constant(1 : i64) : i64
    %102 = llvm.getelementptr %91[0, %101] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %94, %102 : i64, !llvm.ptr
    %103 = llvm.mlir.constant(2 : i64) : i64
    %104 = llvm.getelementptr %91[0, %103] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %95, %104 : i64, !llvm.ptr
    %105 = llvm.mlir.constant(3 : i64) : i64
    %106 = llvm.getelementptr %91[0, %105] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %96, %106 : i64, !llvm.ptr
    %107 = llvm.mlir.constant(4 : i64) : i64
    %108 = llvm.getelementptr %91[0, %107] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %97, %108 : i64, !llvm.ptr
    %109 = llvm.mlir.constant(5 : i64) : i64
    %110 = llvm.getelementptr %91[0, %109] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %98, %110 : i64, !llvm.ptr
    %112 = arith.constant 0 : i32
    %113 = arith.constant 0 : i32
    %114 = arith.constant 0 : i32
    %115 = arith.constant 0 : i32
    %116 = arith.constant 0 : i32
    %117 = arith.constant 0 : i32
    %118 = llvm.mlir.constant(1 : i64) : i64
    %119 = llvm.alloca %118 x !llvm.array<6 x i64> : (i64) -> !llvm.ptr
    %120 = llvm.mlir.zero : !llvm.array<6 x i64>
    llvm.store %120, %119 : !llvm.array<6 x i64>, !llvm.ptr
    %121 = arith.extsi %112 : i32 to i64
    %122 = arith.extsi %113 : i32 to i64
    %123 = arith.extsi %114 : i32 to i64
    %124 = arith.extsi %115 : i32 to i64
    %125 = arith.extsi %116 : i32 to i64
    %126 = arith.extsi %117 : i32 to i64
    %127 = llvm.mlir.constant(0 : i64) : i64
    %128 = llvm.getelementptr %119[0, %127] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %121, %128 : i64, !llvm.ptr
    %129 = llvm.mlir.constant(1 : i64) : i64
    %130 = llvm.getelementptr %119[0, %129] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %122, %130 : i64, !llvm.ptr
    %131 = llvm.mlir.constant(2 : i64) : i64
    %132 = llvm.getelementptr %119[0, %131] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %123, %132 : i64, !llvm.ptr
    %133 = llvm.mlir.constant(3 : i64) : i64
    %134 = llvm.getelementptr %119[0, %133] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %124, %134 : i64, !llvm.ptr
    %135 = llvm.mlir.constant(4 : i64) : i64
    %136 = llvm.getelementptr %119[0, %135] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %125, %136 : i64, !llvm.ptr
    %137 = llvm.mlir.constant(5 : i64) : i64
    %138 = llvm.getelementptr %119[0, %137] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %126, %138 : i64, !llvm.ptr
    %140 = arith.constant 0 : i32
    %141 = arith.constant 0 : i32
    %142 = arith.constant 0 : i32
    %143 = arith.constant 0 : i32
    %144 = arith.constant 0 : i32
    %145 = arith.constant 0 : i32
    %146 = llvm.mlir.constant(1 : i64) : i64
    %147 = llvm.alloca %146 x !llvm.array<6 x i64> : (i64) -> !llvm.ptr
    %148 = llvm.mlir.zero : !llvm.array<6 x i64>
    llvm.store %148, %147 : !llvm.array<6 x i64>, !llvm.ptr
    %149 = arith.extsi %140 : i32 to i64
    %150 = arith.extsi %141 : i32 to i64
    %151 = arith.extsi %142 : i32 to i64
    %152 = arith.extsi %143 : i32 to i64
    %153 = arith.extsi %144 : i32 to i64
    %154 = arith.extsi %145 : i32 to i64
    %155 = llvm.mlir.constant(0 : i64) : i64
    %156 = llvm.getelementptr %147[0, %155] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %149, %156 : i64, !llvm.ptr
    %157 = llvm.mlir.constant(1 : i64) : i64
    %158 = llvm.getelementptr %147[0, %157] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %150, %158 : i64, !llvm.ptr
    %159 = llvm.mlir.constant(2 : i64) : i64
    %160 = llvm.getelementptr %147[0, %159] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %151, %160 : i64, !llvm.ptr
    %161 = llvm.mlir.constant(3 : i64) : i64
    %162 = llvm.getelementptr %147[0, %161] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %152, %162 : i64, !llvm.ptr
    %163 = llvm.mlir.constant(4 : i64) : i64
    %164 = llvm.getelementptr %147[0, %163] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %153, %164 : i64, !llvm.ptr
    %165 = llvm.mlir.constant(5 : i64) : i64
    %166 = llvm.getelementptr %147[0, %165] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %154, %166 : i64, !llvm.ptr
    %168 = arith.constant 0 : i32
    %169 = arith.constant 0 : i32
    %170 = arith.constant 0 : i32
    %171 = arith.constant 0 : i32
    %172 = arith.constant 0 : i32
    %173 = arith.constant 0 : i32
    %174 = llvm.mlir.constant(1 : i64) : i64
    %175 = llvm.alloca %174 x !llvm.array<6 x i64> : (i64) -> !llvm.ptr
    %176 = llvm.mlir.zero : !llvm.array<6 x i64>
    llvm.store %176, %175 : !llvm.array<6 x i64>, !llvm.ptr
    %177 = arith.extsi %168 : i32 to i64
    %178 = arith.extsi %169 : i32 to i64
    %179 = arith.extsi %170 : i32 to i64
    %180 = arith.extsi %171 : i32 to i64
    %181 = arith.extsi %172 : i32 to i64
    %182 = arith.extsi %173 : i32 to i64
    %183 = llvm.mlir.constant(0 : i64) : i64
    %184 = llvm.getelementptr %175[0, %183] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %177, %184 : i64, !llvm.ptr
    %185 = llvm.mlir.constant(1 : i64) : i64
    %186 = llvm.getelementptr %175[0, %185] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %178, %186 : i64, !llvm.ptr
    %187 = llvm.mlir.constant(2 : i64) : i64
    %188 = llvm.getelementptr %175[0, %187] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %179, %188 : i64, !llvm.ptr
    %189 = llvm.mlir.constant(3 : i64) : i64
    %190 = llvm.getelementptr %175[0, %189] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %180, %190 : i64, !llvm.ptr
    %191 = llvm.mlir.constant(4 : i64) : i64
    %192 = llvm.getelementptr %175[0, %191] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %181, %192 : i64, !llvm.ptr
    %193 = llvm.mlir.constant(5 : i64) : i64
    %194 = llvm.getelementptr %175[0, %193] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
    llvm.store %182, %194 : i64, !llvm.ptr
    %195 = arith.constant 0 : i32
    %196 = arith.extsi %195 : i32 to i64
    %197 = llvm.mlir.constant(1 : i64) : i64
    %198 = llvm.alloca %197 x i64 : (i64) -> !llvm.ptr
    llvm.store %196, %198 : i64, !llvm.ptr
    %199 = arith.constant 0 : i32
    %200 = arith.extsi %199 : i32 to i64
    %201 = llvm.mlir.constant(1 : i64) : i64
    %202 = llvm.alloca %201 x i64 : (i64) -> !llvm.ptr
    llvm.store %200, %202 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %203 = llvm.load %202 : !llvm.ptr -> i64
    %204 = arith.constant 6 : i32
    %206 = arith.extsi %204 : i32 to i64
    %205 = arith.cmpi slt, %203, %206 : i64
    cf.cond_br %205, ^bb13, ^bb14
    ^bb13:
      %208 = arith.constant 2 : i32
      %209 = llvm.load %202 : !llvm.ptr -> i64
      %210 = arith.constant 7 : i32
      %212 = arith.extsi %210 : i32 to i64
      %211 = arith.addi %209, %212 : i64
      %213 = arith.extsi %208 : i32 to i64
      %207 = func.call @modpow(%213, %211, %71) : (i64, i64, i64) -> i64
      %214 = llvm.load %202 : !llvm.ptr -> i64
      %215 = llvm.getelementptr %119[0, %214] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
      llvm.store %207, %215 : i64, !llvm.ptr
      %216 = arith.constant 1 : i32
      %218 = arith.extsi %216 : i32 to i64
      %217 = arith.addi %218, %75 : i64
      %220 = llvm.load %202 : !llvm.ptr -> i64
      %221 = llvm.getelementptr %91[0, %220] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
      %219 = llvm.load %221 : !llvm.ptr -> i64
      %222 = arith.addi %217, %219 : i64
      %223 = arith.remsi %222, %71 : i64
      %224 = llvm.load %202 : !llvm.ptr -> i64
      %225 = llvm.getelementptr %147[0, %224] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
      llvm.store %223, %225 : i64, !llvm.ptr
      %226 = llvm.load %202 : !llvm.ptr -> i64
      %227 = arith.subi %73, %226 : i64
      %228 = arith.constant 6 : i32
      %230 = arith.extsi %228 : i32 to i64
      %229 = arith.subi %227, %230 : i64
      %231 = arith.constant 6 : i32
      %233 = arith.extsi %231 : i32 to i64
      %232 = arith.divsi %229, %233 : i64
      %234 = arith.constant 1 : i32
      %236 = arith.extsi %234 : i32 to i64
      %235 = arith.addi %232, %236 : i64
      %237 = arith.divsi %235, %78 : i64
      %238 = llvm.load %198 : !llvm.ptr -> i64
      %239 = arith.muli %237, %77 : i64
      %240 = arith.addi %238, %239 : i64
      llvm.store %240, %198 : i64, !llvm.ptr
      %241 = arith.muli %237, %78 : i64
      %242 = arith.subi %235, %241 : i64
      %243 = llvm.load %202 : !llvm.ptr -> i64
      %244 = llvm.getelementptr %175[0, %243] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
      llvm.store %242, %244 : i64, !llvm.ptr
      %245 = llvm.load %202 : !llvm.ptr -> i64
      %246 = arith.constant 1 : i32
      %248 = arith.extsi %246 : i32 to i64
      %247 = arith.addi %245, %248 : i64
      llvm.store %247, %202 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %249 = arith.constant 0 : i32
    %250 = arith.extsi %249 : i32 to i64
    %251 = llvm.mlir.constant(1 : i64) : i64
    %252 = llvm.alloca %251 x i64 : (i64) -> !llvm.ptr
    llvm.store %250, %252 : i64, !llvm.ptr
    %253 = arith.constant 1 : i32
    %254 = arith.extsi %253 : i32 to i64
    %255 = llvm.mlir.constant(1 : i64) : i64
    %256 = llvm.alloca %255 x i64 : (i64) -> !llvm.ptr
    llvm.store %254, %256 : i64, !llvm.ptr
    %257 = arith.constant 0 : i32
    %258 = arith.extsi %257 : i32 to i64
    %259 = llvm.mlir.constant(1 : i64) : i64
    %260 = llvm.alloca %259 x i64 : (i64) -> !llvm.ptr
    llvm.store %258, %260 : i64, !llvm.ptr
    cf.br ^bb15
    ^bb15:
    %261 = llvm.load %260 : !llvm.ptr -> i64
    %262 = arith.cmpi slt, %261, %77 : i64
    cf.cond_br %262, ^bb16, ^bb17
    ^bb16:
      %263 = arith.constant 0 : i32
      %264 = arith.extsi %263 : i32 to i64
      llvm.store %264, %202 : i64, !llvm.ptr
      cf.br ^bb18
      ^bb18:
      %265 = llvm.load %202 : !llvm.ptr -> i64
      %266 = arith.constant 6 : i32
      %268 = arith.extsi %266 : i32 to i64
      %267 = arith.cmpi slt, %265, %268 : i64
      cf.cond_br %267, ^bb19, ^bb20
      ^bb19:
        %270 = llvm.load %202 : !llvm.ptr -> i64
        %271 = llvm.getelementptr %119[0, %270] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
        %269 = llvm.load %271 : !llvm.ptr -> i64
        %272 = llvm.load %256 : !llvm.ptr -> i64
        %273 = arith.muli %269, %272 : i64
        %274 = arith.remsi %273, %71 : i64
        %276 = llvm.load %202 : !llvm.ptr -> i64
        %277 = llvm.getelementptr %147[0, %276] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
        %275 = llvm.load %277 : !llvm.ptr -> i64
        %278 = arith.subi %274, %275 : i64
        %279 = arith.remsi %278, %71 : i64
        %280 = arith.addi %279, %71 : i64
        %281 = arith.remsi %280, %71 : i64
        %282 = llvm.mlir.constant(1 : i64) : i64
        %283 = llvm.alloca %282 x i64 : (i64) -> !llvm.ptr
        llvm.store %281, %283 : i64, !llvm.ptr
        %284 = llvm.load %283 : !llvm.ptr -> i64
        %285 = arith.muli %284, %79 : i64
        %286 = arith.remsi %285, %71 : i64
        llvm.store %286, %283 : i64, !llvm.ptr
        %287 = llvm.load %283 : !llvm.ptr -> i64
        %288 = llvm.load %260 : !llvm.ptr -> i64
        %289 = arith.subi %287, %288 : i64
        %290 = llvm.mlir.constant(1 : i64) : i64
        %291 = llvm.alloca %290 x i64 : (i64) -> !llvm.ptr
        llvm.store %289, %291 : i64, !llvm.ptr
        %292 = llvm.load %291 : !llvm.ptr -> i64
        %293 = arith.constant 0 : i32
        %295 = arith.extsi %293 : i32 to i64
        %294 = arith.cmpi slt, %292, %295 : i64
        cf.cond_br %294, ^bb21, ^bb22
        ^bb21:
          %296 = llvm.load %291 : !llvm.ptr -> i64
          %297 = arith.addi %296, %71 : i64
          llvm.store %297, %291 : i64, !llvm.ptr
          cf.br ^bb23
        ^bb22:
          cf.br ^bb23
        ^bb23:
        %298 = llvm.load %291 : !llvm.ptr -> i64
        %299 = arith.muli %298, %82 : i64
        %300 = arith.remsi %299, %71 : i64
        %301 = llvm.load %260 : !llvm.ptr -> i64
        %302 = arith.muli %77, %300 : i64
        %303 = arith.addi %301, %302 : i64
        %305 = llvm.load %202 : !llvm.ptr -> i64
        %306 = llvm.getelementptr %175[0, %305] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<6 x i64>
        %304 = llvm.load %306 : !llvm.ptr -> i64
        %307 = arith.cmpi slt, %303, %304 : i64
        cf.cond_br %307, ^bb24, ^bb25
        ^bb24:
          %308 = llvm.load %252 : !llvm.ptr -> i64
          %309 = arith.constant 1 : i32
          %311 = arith.extsi %309 : i32 to i64
          %310 = arith.addi %308, %311 : i64
          llvm.store %310, %252 : i64, !llvm.ptr
          cf.br ^bb26
        ^bb25:
          cf.br ^bb26
        ^bb26:
        %312 = llvm.load %202 : !llvm.ptr -> i64
        %313 = arith.constant 1 : i32
        %315 = arith.extsi %313 : i32 to i64
        %314 = arith.addi %312, %315 : i64
        llvm.store %314, %202 : i64, !llvm.ptr
        cf.br ^bb18
      ^bb20:
      %316 = llvm.load %256 : !llvm.ptr -> i64
      %317 = arith.constant 64 : i32
      %319 = arith.extsi %317 : i32 to i64
      %318 = arith.muli %316, %319 : i64
      %320 = arith.remsi %318, %71 : i64
      llvm.store %320, %256 : i64, !llvm.ptr
      %321 = llvm.load %260 : !llvm.ptr -> i64
      %322 = arith.constant 1 : i32
      %324 = arith.extsi %322 : i32 to i64
      %323 = arith.addi %321, %324 : i64
      llvm.store %323, %260 : i64, !llvm.ptr
      cf.br ^bb15
    ^bb17:
    %325 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %326 = llvm.load %198 : !llvm.ptr -> i64
    %327 = llvm.load %252 : !llvm.ptr -> i64
    %328 = arith.addi %326, %327 : i64
    %329 = llvm.call @printf(%325, %328) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %330 = arith.constant 0 : i32
    func.return %330 : i32
  }
}