Problem 498

Remainder of Polynomial Division — C(n,m,d)=C(n,d)*C(n-d-1,m-d-1) via Lucas.

Answer472294837
Output472294837
StatusPASS
Native helperno
Runtime10 ms
Peak memory10992 KB
Time complexityO(n) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)?
Space complexityO(n)?
ApproachFlow solutionNot curated
VerdictUnknown

Flow source

# Project Euler 498
# Remainder of Polynomial Division — C(n,m,d)=C(n,d)*C(n-d-1,m-d-1) via Lucas.

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
}

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 {
            let t: i128 = (r as i128) * (b as i128) % (mod as i128)
            r = t as i64
        }
        let t2: i128 = (b as i128) * (b as i128) % (mod as i128)
        b = t2 as i64
        e = e / 2
    }
    return r
}

function nCk_small(nn: i64, kk: i64, fact: ptr<i64>, invfact: ptr<i64>, p: i64) -> i64 {
    if kk < 0 || kk > nn { return 0 }
    return ((fact[nn] * invfact[kk]) % p) * invfact[nn - kk] % p
}

function nCk_lucas(nn0: i64, kk0: i64, fact: ptr<i64>, invfact: ptr<i64>, p: i64) -> i64 {
    let mut nn: i64 = nn0
    let mut kk: i64 = kk0
    let mut res: i64 = 1
    while nn > 0 || kk > 0 {
        let ni: i64 = nn % p
        let ki: i64 = kk % p
        if ki > ni { return 0 }
        res = (res * nCk_small(ni, ki, fact, invfact, p)) % p
        nn = nn / p
        kk = kk / p
    }
    return res
}

function main() -> i32 {
    let n: i64 = 10000000000000
    let m: i64 = 1000000000000
    let d: i64 = 10000
    let p: i64 = 999999937
    # max Lucas digit for these params is n%p = 630000
    let max_digit: i64 = 630000
    let fact: ptr<i64> = calloc(max_digit + 1, 8)
    let invfact: ptr<i64> = calloc(max_digit + 1, 8)
    if fact == null || invfact == null { return 1 }
    fact[0] = 1
    let mut i: i64 = 1
    while i <= max_digit {
        fact[i] = (fact[i - 1] * i) % p
        i = i + 1
    }
    invfact[max_digit] = modpow(fact[max_digit], p - 2, p)
    i = max_digit
    while i > 0 {
        invfact[i - 1] = (invfact[i] * i) % p
        i = i - 1
    }
    let part1: i64 = nCk_lucas(n, d, fact, invfact, p)
    let part2: i64 = nCk_lucas(n - d - 1, m - d - 1, fact, invfact, p)
    printf("%lld\n", (part1 * part2) % p)
    free(invfact)
    free(fact)
    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 modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod);
int64_t nCk_small_i64_i64_ptr_i64_ptr_i64_i64(int64_t nn, int64_t kk, int64_t* fact, int64_t* invfact, int64_t p);
int64_t nCk_lucas_i64_i64_ptr_i64_ptr_i64_i64(int64_t nn0, int64_t kk0, int64_t* fact, int64_t* invfact, int64_t p);
int32_t main(void);



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) {
            __int128 t = FLOW_CHECKED_MOD(((((__int128)(r)) * ((__int128)(b)))), (((__int128)(mod))));
            r = ((int64_t)(t));
        }
        __int128 t2 = FLOW_CHECKED_MOD(((((__int128)(b)) * ((__int128)(b)))), (((__int128)(mod))));
        b = ((int64_t)(t2));
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return r;
}

int64_t nCk_small_i64_i64_ptr_i64_ptr_i64_i64(int64_t nn, int64_t kk, int64_t* fact, int64_t* invfact, int64_t p) {
    if ((kk < 0 || kk > nn)) {
        return 0;
    }
    return FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((fact[nn] * invfact[kk])), (p)) * invfact[(nn - kk)])), (p));
}

int64_t nCk_lucas_i64_i64_ptr_i64_ptr_i64_i64(int64_t nn0, int64_t kk0, int64_t* fact, int64_t* invfact, int64_t p) {
    int64_t nn = nn0;
    int64_t kk = kk0;
    int64_t res = 1;
    while ((nn > 0 || kk > 0)) {
        int64_t ni = FLOW_CHECKED_MOD((nn), (p));
        int64_t ki = FLOW_CHECKED_MOD((kk), (p));
        if (ki > ni) {
            return 0;
        }
        res = FLOW_CHECKED_MOD(((res * nCk_small_i64_i64_ptr_i64_ptr_i64_i64(ni, ki, fact, invfact, p))), (p));
        nn = FLOW_CHECKED_DIV((nn), (p));
        kk = FLOW_CHECKED_DIV((kk), (p));
    }
    return res;
}

int32_t main(void) {
    int64_t n = 10000000000000;
    int64_t m = 1000000000000;
    int64_t d = 10000;
    int64_t p = 999999937;
    int64_t max_digit = 630000;
    int64_t* fact = (int64_t*)(calloc((max_digit + 1), 8));
    int64_t* invfact = (int64_t*)(calloc((max_digit + 1), 8));
    if ((fact == NULL || invfact == NULL)) {
        return 1;
    }
    fact[0] = 1;
    int64_t i = 1;
    while (i <= max_digit) {
        fact[i] = FLOW_CHECKED_MOD(((fact[(i - 1)] * i)), (p));
        i = (i + 1);
    }
    invfact[max_digit] = modpow_i64_i64_i64(fact[max_digit], (p - 2), p);
    i = max_digit;
    while (i > 0) {
        invfact[(i - 1)] = FLOW_CHECKED_MOD(((invfact[i] * i)), (p));
        i = (i - 1);
    }
    int64_t part1 = nCk_lucas_i64_i64_ptr_i64_ptr_i64_i64(n, d, fact, invfact, p);
    int64_t part2 = nCk_lucas_i64_i64_ptr_i64_ptr_i64_i64(((n - d) - 1), ((m - d) - 1), fact, invfact, p);
    printf("%lld\n", FLOW_CHECKED_MOD(((part1 * part2)), (p)));
    free(invfact);
    free(fact);
    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 private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func @modpow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %0 = arith.constant 1 : i32
    %1 = arith.extsi %0 : i32 to i64
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %1, %3 : i64, !llvm.ptr
    %4 = arith.remsi %arg0, %arg2 : i64
    %5 = llvm.mlir.constant(1 : i64) : i64
    %6 = llvm.alloca %5 x i64 : (i64) -> !llvm.ptr
    llvm.store %4, %6 : i64, !llvm.ptr
    %7 = llvm.mlir.constant(1 : i64) : i64
    %8 = llvm.alloca %7 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %8 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %9 = llvm.load %8 : !llvm.ptr -> i64
    %10 = arith.constant 0 : i32
    %12 = arith.extsi %10 : i32 to i64
    %11 = arith.cmpi sgt, %9, %12 : i64
    cf.cond_br %11, ^bb1, ^bb2
    ^bb1:
      %13 = llvm.load %8 : !llvm.ptr -> i64
      %14 = arith.constant 2 : i32
      %16 = arith.extsi %14 : i32 to i64
      %15 = arith.remsi %13, %16 : i64
      %17 = arith.constant 1 : i32
      %19 = arith.extsi %17 : i32 to i64
      %18 = arith.cmpi eq, %15, %19 : i64
      cf.cond_br %18, ^bb3, ^bb4
      ^bb3:
        %20 = llvm.load %3 : !llvm.ptr -> i64
        %21 = arith.extsi %20 : i64 to i128
        %22 = llvm.load %6 : !llvm.ptr -> i64
        %23 = arith.extsi %22 : i64 to i128
        %25 = arith.trunci %21 : i128 to i64
        %26 = arith.trunci %23 : i128 to i64
        %24 = arith.muli %25, %26 : i64
        %27 = arith.extsi %arg2 : i64 to i128
        %29 = arith.trunci %27 : i128 to i64
        %28 = arith.remsi %24, %29 : i64
        %30 = arith.extsi %28 : i64 to i128
        %31 = arith.trunci %30 : i128 to i64
        llvm.store %31, %3 : i64, !llvm.ptr
        cf.br ^bb5
      ^bb4:
        cf.br ^bb5
      ^bb5:
      %32 = llvm.load %6 : !llvm.ptr -> i64
      %33 = arith.extsi %32 : i64 to i128
      %34 = llvm.load %6 : !llvm.ptr -> i64
      %35 = arith.extsi %34 : i64 to i128
      %37 = arith.trunci %33 : i128 to i64
      %38 = arith.trunci %35 : i128 to i64
      %36 = arith.muli %37, %38 : i64
      %39 = arith.extsi %arg2 : i64 to i128
      %41 = arith.trunci %39 : i128 to i64
      %40 = arith.remsi %36, %41 : i64
      %42 = arith.extsi %40 : i64 to i128
      %43 = arith.trunci %42 : i128 to i64
      llvm.store %43, %6 : i64, !llvm.ptr
      %44 = llvm.load %8 : !llvm.ptr -> i64
      %45 = arith.constant 2 : i32
      %47 = arith.extsi %45 : i32 to i64
      %46 = arith.divsi %44, %47 : i64
      llvm.store %46, %8 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %48 = llvm.load %3 : !llvm.ptr -> i64
    func.return %48 : i64
  }
  func.func @nCk_small(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr, %arg3: !llvm.ptr, %arg4: i64) -> i64 {
    %49 = arith.constant 0 : i32
    %51 = arith.extsi %49 : i32 to i64
    %50 = arith.cmpi slt, %arg1, %51 : i64
    %52 = scf.if %50 -> (i1) {
      %53 = arith.constant true
      scf.yield %53 : i1
    } else {
      %54 = arith.cmpi sgt, %arg1, %arg0 : i64
      scf.yield %54 : i1
    }
    cf.cond_br %52, ^bb6, ^bb7
    ^bb6:
      %55 = arith.constant 0 : i32
      %56 = arith.extsi %55 : i32 to i64
      func.return %56 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %58 = llvm.getelementptr %arg2[%arg0] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %57 = llvm.load %58 : !llvm.ptr -> i64
    %60 = llvm.getelementptr %arg3[%arg1] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %59 = llvm.load %60 : !llvm.ptr -> i64
    %61 = arith.muli %57, %59 : i64
    %62 = arith.remsi %61, %arg4 : i64
    %64 = arith.subi %arg0, %arg1 : i64
    %65 = llvm.getelementptr %arg3[%64] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %63 = llvm.load %65 : !llvm.ptr -> i64
    %66 = arith.muli %62, %63 : i64
    %67 = arith.remsi %66, %arg4 : i64
    func.return %67 : i64
  }
  func.func @nCk_lucas(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr, %arg3: !llvm.ptr, %arg4: i64) -> i64 {
    %68 = llvm.mlir.constant(1 : i64) : i64
    %69 = llvm.alloca %68 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %69 : i64, !llvm.ptr
    %70 = llvm.mlir.constant(1 : i64) : i64
    %71 = llvm.alloca %70 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %71 : i64, !llvm.ptr
    %72 = arith.constant 1 : i32
    %73 = arith.extsi %72 : i32 to i64
    %74 = llvm.mlir.constant(1 : i64) : i64
    %75 = llvm.alloca %74 x i64 : (i64) -> !llvm.ptr
    llvm.store %73, %75 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %76 = llvm.load %69 : !llvm.ptr -> i64
    %77 = arith.constant 0 : i32
    %79 = arith.extsi %77 : i32 to i64
    %78 = arith.cmpi sgt, %76, %79 : i64
    %80 = scf.if %78 -> (i1) {
      %81 = arith.constant true
      scf.yield %81 : i1
    } else {
      %82 = llvm.load %71 : !llvm.ptr -> i64
      %83 = arith.constant 0 : i32
      %85 = arith.extsi %83 : i32 to i64
      %84 = arith.cmpi sgt, %82, %85 : i64
      scf.yield %84 : i1
    }
    cf.cond_br %80, ^bb10, ^bb11
    ^bb10:
      %86 = llvm.load %69 : !llvm.ptr -> i64
      %87 = arith.remsi %86, %arg4 : i64
      %88 = llvm.load %71 : !llvm.ptr -> i64
      %89 = arith.remsi %88, %arg4 : i64
      %90 = arith.cmpi sgt, %89, %87 : i64
      cf.cond_br %90, ^bb12, ^bb13
      ^bb12:
        %91 = arith.constant 0 : i32
        %92 = arith.extsi %91 : i32 to i64
        func.return %92 : i64
      ^bb13:
        cf.br ^bb14
      ^bb14:
      %93 = llvm.load %75 : !llvm.ptr -> i64
      %94 = func.call @nCk_small(%87, %89, %arg2, %arg3, %arg4) : (i64, i64, !llvm.ptr, !llvm.ptr, i64) -> i64
      %95 = arith.muli %93, %94 : i64
      %96 = arith.remsi %95, %arg4 : i64
      llvm.store %96, %75 : i64, !llvm.ptr
      %97 = llvm.load %69 : !llvm.ptr -> i64
      %98 = arith.divsi %97, %arg4 : i64
      llvm.store %98, %69 : i64, !llvm.ptr
      %99 = llvm.load %71 : !llvm.ptr -> i64
      %100 = arith.divsi %99, %arg4 : i64
      llvm.store %100, %71 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %101 = llvm.load %75 : !llvm.ptr -> i64
    func.return %101 : i64
  }
  func.func @main() -> i32 {
    %102 = arith.constant 9995705032704 : i32
    %103 = arith.extsi %102 : i32 to i64
    %104 = arith.constant 995705032704 : i32
    %105 = arith.extsi %104 : i32 to i64
    %106 = arith.constant 10000 : i32
    %107 = arith.extsi %106 : i32 to i64
    %108 = arith.constant 999999937 : i32
    %109 = arith.extsi %108 : i32 to i64
    %110 = arith.constant 630000 : i32
    %111 = arith.extsi %110 : i32 to i64
    %113 = arith.constant 1 : i32
    %115 = arith.extsi %113 : i32 to i64
    %114 = arith.addi %111, %115 : i64
    %116 = arith.constant 8 : i32
    %117 = arith.extsi %116 : i32 to i64
    %112 = func.call @calloc(%114, %117) : (i64, i64) -> !llvm.ptr
    %119 = arith.constant 1 : i32
    %121 = arith.extsi %119 : i32 to i64
    %120 = arith.addi %111, %121 : i64
    %122 = arith.constant 8 : i32
    %123 = arith.extsi %122 : i32 to i64
    %118 = func.call @calloc(%120, %123) : (i64, i64) -> !llvm.ptr
    %124 = llvm.mlir.zero : !llvm.ptr
    %125 = llvm.icmp "eq" %112, %124 : !llvm.ptr
    %126 = scf.if %125 -> (i1) {
      %127 = arith.constant true
      scf.yield %127 : i1
    } else {
      %128 = llvm.mlir.zero : !llvm.ptr
      %129 = llvm.icmp "eq" %118, %128 : !llvm.ptr
      scf.yield %129 : i1
    }
    cf.cond_br %126, ^bb15, ^bb16
    ^bb15:
      %130 = arith.constant 1 : i32
      func.return %130 : i32
    ^bb16:
      cf.br ^bb17
    ^bb17:
    %131 = arith.constant 1 : i32
    %132 = arith.constant 0 : i32
    %133 = arith.extsi %131 : i32 to i64
    %134 = arith.extsi %132 : i32 to i64
    %135 = llvm.getelementptr %112[%134] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %133, %135 : i64, !llvm.ptr
    %136 = arith.constant 1 : i32
    %137 = arith.extsi %136 : i32 to i64
    %138 = llvm.mlir.constant(1 : i64) : i64
    %139 = llvm.alloca %138 x i64 : (i64) -> !llvm.ptr
    llvm.store %137, %139 : i64, !llvm.ptr
    cf.br ^bb18
    ^bb18:
    %140 = llvm.load %139 : !llvm.ptr -> i64
    %141 = arith.cmpi sle, %140, %111 : i64
    cf.cond_br %141, ^bb19, ^bb20
    ^bb19:
      %143 = llvm.load %139 : !llvm.ptr -> i64
      %144 = arith.constant 1 : i32
      %146 = arith.extsi %144 : i32 to i64
      %145 = arith.subi %143, %146 : i64
      %147 = llvm.getelementptr %112[%145] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %142 = llvm.load %147 : !llvm.ptr -> i64
      %148 = llvm.load %139 : !llvm.ptr -> i64
      %149 = arith.muli %142, %148 : i64
      %150 = arith.remsi %149, %109 : i64
      %151 = llvm.load %139 : !llvm.ptr -> i64
      %152 = llvm.getelementptr %112[%151] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %150, %152 : i64, !llvm.ptr
      %153 = llvm.load %139 : !llvm.ptr -> i64
      %154 = arith.constant 1 : i32
      %156 = arith.extsi %154 : i32 to i64
      %155 = arith.addi %153, %156 : i64
      llvm.store %155, %139 : i64, !llvm.ptr
      cf.br ^bb18
    ^bb20:
    %159 = llvm.getelementptr %112[%111] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %158 = llvm.load %159 : !llvm.ptr -> i64
    %160 = arith.constant 2 : i32
    %162 = arith.extsi %160 : i32 to i64
    %161 = arith.subi %109, %162 : i64
    %157 = func.call @modpow(%158, %161, %109) : (i64, i64, i64) -> i64
    %163 = llvm.getelementptr %118[%111] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %157, %163 : i64, !llvm.ptr
    llvm.store %111, %139 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %164 = llvm.load %139 : !llvm.ptr -> i64
    %165 = arith.constant 0 : i32
    %167 = arith.extsi %165 : i32 to i64
    %166 = arith.cmpi sgt, %164, %167 : i64
    cf.cond_br %166, ^bb22, ^bb23
    ^bb22:
      %169 = llvm.load %139 : !llvm.ptr -> i64
      %170 = llvm.getelementptr %118[%169] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %168 = llvm.load %170 : !llvm.ptr -> i64
      %171 = llvm.load %139 : !llvm.ptr -> i64
      %172 = arith.muli %168, %171 : i64
      %173 = arith.remsi %172, %109 : i64
      %174 = llvm.load %139 : !llvm.ptr -> i64
      %175 = arith.constant 1 : i32
      %177 = arith.extsi %175 : i32 to i64
      %176 = arith.subi %174, %177 : i64
      %178 = llvm.getelementptr %118[%176] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %173, %178 : i64, !llvm.ptr
      %179 = llvm.load %139 : !llvm.ptr -> i64
      %180 = arith.constant 1 : i32
      %182 = arith.extsi %180 : i32 to i64
      %181 = arith.subi %179, %182 : i64
      llvm.store %181, %139 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %183 = func.call @nCk_lucas(%103, %107, %112, %118, %109) : (i64, i64, !llvm.ptr, !llvm.ptr, i64) -> i64
    %185 = arith.subi %103, %107 : i64
    %186 = arith.constant 1 : i32
    %188 = arith.extsi %186 : i32 to i64
    %187 = arith.subi %185, %188 : i64
    %189 = arith.subi %105, %107 : i64
    %190 = arith.constant 1 : i32
    %192 = arith.extsi %190 : i32 to i64
    %191 = arith.subi %189, %192 : i64
    %184 = func.call @nCk_lucas(%187, %191, %112, %118, %109) : (i64, i64, !llvm.ptr, !llvm.ptr, i64) -> i64
    %193 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %194 = arith.muli %183, %184 : i64
    %195 = arith.remsi %194, %109 : i64
    %196 = llvm.call @printf(%193, %195) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%118) : (!llvm.ptr) -> ()
    func.call @free(%112) : (!llvm.ptr) -> ()
    %199 = arith.constant 0 : i32
    func.return %199 : i32
  }
}