Problem 960

Spanning forests / Cayley: F(100) mod 10^9+7.

Answer243559751
Output243559751
StatusPASS
Native helperno
Runtime0 ms
Peak memory1072 KB
Time complexityO(n) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)O(n log n)
Space complexityO(n)O(n)
ApproachFlow solutionModular DP or matrix exponentiation
VerdictOptimal

Flow source

# Project Euler 960
# Spanning forests / Cayley: F(100) mod 10^9+7.

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

const MOD: i64 = 1000000007

function modmul(a: i64, b: i64) -> i64 {
    return ((a as i128) * (b as i128) % (MOD as i128)) as i64
}

function modpow(base0: i64, exp0: i64) -> i64 {
    let mut r: i64 = 1
    let mut b: i64 = base0 % MOD
    let mut e: i64 = exp0
    while e > 0 {
        if (e & 1) != 0 { r = modmul(r, b) }
        b = modmul(b, b)
        e = e >> 1
    }
    return r
}

function F(n: i64) -> i64 {
    let mut fact: ptr<i64> = calloc(n + 1, 8)
    let mut invfact: ptr<i64> = calloc(n + 1, 8)
    fact[0] = 1
    let mut i: i64 = 1
    while i <= n {
        fact[i] = modmul(fact[i - 1], i)
        i = i + 1
    }
    invfact[n] = modpow(fact[n], MOD - 2)
    i = n
    while i > 0 {
        invfact[i - 1] = modmul(invfact[i], i)
        i = i - 1
    }
    let mut S: i64 = 0
    let inv2: i64 = (MOD + 1) / 2
    let mut k: i64 = 1
    while k <= n / 2 {
        let mut trees_k: i64 = 1
        if k > 1 { trees_k = modpow(k, k - 2) }
        let trees_nk: i64 = modpow(n - k, n - k - 2)
        let mut ways: i64 = modmul(fact[n], modmul(invfact[k], invfact[n - k]))
        ways = modmul(ways, trees_k)
        ways = modmul(ways, trees_nk)
        ways = modmul(ways, k)
        ways = modmul(ways, n - k)
        if 2 * k == n { ways = modmul(ways, inv2) }
        S = (S + modmul(k, ways)) % MOD
        k = k + 1
    }
    let ans: i64 = modmul(S, fact[n - 1])
    free(fact)
    free(invfact)
    return ans
}

function main() -> i32 {
    printf("%lld\n", F(100))
    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 modmul_i64_i64(int64_t a, int64_t b);
int64_t modpow_i64_i64(int64_t base0, int64_t exp0);
int64_t F_i64(int64_t n);
int32_t main(void);

static const int64_t MOD = 1000000007;



int64_t modmul_i64_i64(int64_t a, int64_t b) {
    return ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(a)) * ((__int128)(b)))), (((__int128)(MOD))))));
}

int64_t modpow_i64_i64(int64_t base0, int64_t exp0) {
    int64_t r = 1;
    int64_t b = FLOW_CHECKED_MOD((base0), (MOD));
    int64_t e = exp0;
    while (e > 0) {
        if ((e & 1) != 0) {
            r = modmul_i64_i64(r, b);
        }
        b = modmul_i64_i64(b, b);
        e = FLOW_CHECKED_SHR((e), (1));
    }
    return r;
}

int64_t F_i64(int64_t n) {
    int64_t* fact = (int64_t*)(calloc((n + 1), 8));
    int64_t* invfact = (int64_t*)(calloc((n + 1), 8));
    fact[0] = 1;
    int64_t i = 1;
    while (i <= n) {
        fact[i] = modmul_i64_i64(fact[(i - 1)], i);
        i = (i + 1);
    }
    invfact[n] = modpow_i64_i64(fact[n], (MOD - 2));
    i = n;
    while (i > 0) {
        invfact[(i - 1)] = modmul_i64_i64(invfact[i], i);
        i = (i - 1);
    }
    int64_t S = 0;
    int64_t inv2 = FLOW_CHECKED_DIV(((MOD + 1)), (2));
    int64_t k = 1;
    while (k <= FLOW_CHECKED_DIV((n), (2))) {
        int64_t trees_k = 1;
        if (k > 1) {
            trees_k = modpow_i64_i64(k, (k - 2));
        }
        int64_t trees_nk = modpow_i64_i64((n - k), ((n - k) - 2));
        int64_t ways = modmul_i64_i64(fact[n], modmul_i64_i64(invfact[k], invfact[(n - k)]));
        ways = modmul_i64_i64(ways, trees_k);
        ways = modmul_i64_i64(ways, trees_nk);
        ways = modmul_i64_i64(ways, k);
        ways = modmul_i64_i64(ways, (n - k));
        if ((2 * k) == n) {
            ways = modmul_i64_i64(ways, inv2);
        }
        S = FLOW_CHECKED_MOD(((S + modmul_i64_i64(k, ways))), (MOD));
        k = (k + 1);
    }
    int64_t ans = modmul_i64_i64(S, fact[(n - 1)]);
    free(fact);
    free(invfact);
    return ans;
}

int32_t main(void) {
    printf("%lld\n", F_i64(100));
    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) -> ()
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
  func.func @modmul(%arg0: i64, %arg1: i64) -> i64 {
    %0 = arith.extsi %arg0 : i64 to i128
    %1 = arith.extsi %arg1 : i64 to i128
    %3 = arith.trunci %0 : i128 to i64
    %4 = arith.trunci %1 : i128 to i64
    %2 = arith.muli %3, %4 : i64
    %5 = llvm.mlir.addressof @MOD : !llvm.ptr
    %6 = llvm.load %5 : !llvm.ptr -> i64
    %7 = arith.extsi %6 : i64 to i128
    %9 = arith.trunci %7 : i128 to i64
    %8 = arith.remsi %2, %9 : i64
    func.return %8 : i64
  }
  func.func @modpow(%arg0: i64, %arg1: i64) -> i64 {
    %10 = arith.constant 1 : i32
    %11 = arith.extsi %10 : i32 to i64
    %12 = llvm.mlir.constant(1 : i64) : i64
    %13 = llvm.alloca %12 x i64 : (i64) -> !llvm.ptr
    llvm.store %11, %13 : i64, !llvm.ptr
    %14 = llvm.mlir.addressof @MOD : !llvm.ptr
    %15 = llvm.load %14 : !llvm.ptr -> i64
    %16 = arith.remsi %arg0, %15 : i64
    %17 = llvm.mlir.constant(1 : i64) : i64
    %18 = llvm.alloca %17 x i64 : (i64) -> !llvm.ptr
    llvm.store %16, %18 : i64, !llvm.ptr
    %19 = llvm.mlir.constant(1 : i64) : i64
    %20 = llvm.alloca %19 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %20 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %21 = llvm.load %20 : !llvm.ptr -> i64
    %22 = arith.constant 0 : i32
    %24 = arith.extsi %22 : i32 to i64
    %23 = arith.cmpi sgt, %21, %24 : i64
    cf.cond_br %23, ^bb1, ^bb2
    ^bb1:
      %25 = llvm.load %20 : !llvm.ptr -> i64
      %26 = arith.constant 1 : i32
      %28 = arith.extsi %26 : i32 to i64
      %27 = arith.andi %25, %28 : i64
      %29 = arith.constant 0 : i32
      %31 = arith.extsi %29 : i32 to i64
      %30 = arith.cmpi ne, %27, %31 : i64
      cf.cond_br %30, ^bb3, ^bb4
      ^bb3:
        %33 = llvm.load %13 : !llvm.ptr -> i64
        %34 = llvm.load %18 : !llvm.ptr -> i64
        %32 = func.call @modmul(%33, %34) : (i64, i64) -> i64
        llvm.store %32, %13 : i64, !llvm.ptr
        cf.br ^bb5
      ^bb4:
        cf.br ^bb5
      ^bb5:
      %36 = llvm.load %18 : !llvm.ptr -> i64
      %37 = llvm.load %18 : !llvm.ptr -> i64
      %35 = func.call @modmul(%36, %37) : (i64, i64) -> i64
      llvm.store %35, %18 : i64, !llvm.ptr
      %38 = llvm.load %20 : !llvm.ptr -> i64
      %39 = arith.constant 1 : i32
      %41 = arith.extsi %39 : i32 to i64
      %40 = arith.shrsi %38, %41 : i64
      llvm.store %40, %20 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %42 = llvm.load %13 : !llvm.ptr -> i64
    func.return %42 : i64
  }
  func.func @F(%arg0: i64) -> i64 {
    %44 = arith.constant 1 : i32
    %46 = arith.extsi %44 : i32 to i64
    %45 = arith.addi %arg0, %46 : i64
    %47 = arith.constant 8 : i32
    %48 = arith.extsi %47 : i32 to i64
    %43 = func.call @calloc(%45, %48) : (i64, i64) -> !llvm.ptr
    %49 = llvm.mlir.constant(1 : i64) : i64
    %50 = llvm.alloca %49 x !llvm.ptr : (i64) -> !llvm.ptr
    llvm.store %43, %50 : !llvm.ptr, !llvm.ptr
    %52 = arith.constant 1 : i32
    %54 = arith.extsi %52 : i32 to i64
    %53 = arith.addi %arg0, %54 : i64
    %55 = arith.constant 8 : i32
    %56 = arith.extsi %55 : i32 to i64
    %51 = func.call @calloc(%53, %56) : (i64, i64) -> !llvm.ptr
    %57 = llvm.mlir.constant(1 : i64) : i64
    %58 = llvm.alloca %57 x !llvm.ptr : (i64) -> !llvm.ptr
    llvm.store %51, %58 : !llvm.ptr, !llvm.ptr
    %59 = arith.constant 1 : i32
    %60 = llvm.load %50 : !llvm.ptr -> !llvm.ptr
    %61 = arith.constant 0 : i32
    %62 = arith.extsi %59 : i32 to i64
    %63 = arith.extsi %61 : i32 to i64
    %64 = llvm.getelementptr %60[%63] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %62, %64 : i64, !llvm.ptr
    %65 = arith.constant 1 : i32
    %66 = arith.extsi %65 : i32 to i64
    %67 = llvm.mlir.constant(1 : i64) : i64
    %68 = llvm.alloca %67 x i64 : (i64) -> !llvm.ptr
    llvm.store %66, %68 : i64, !llvm.ptr
    cf.br ^bb6
    ^bb6:
    %69 = llvm.load %68 : !llvm.ptr -> i64
    %70 = arith.cmpi sle, %69, %arg0 : i64
    cf.cond_br %70, ^bb7, ^bb8
    ^bb7:
      %73 = llvm.load %50 : !llvm.ptr -> !llvm.ptr
      %74 = llvm.load %68 : !llvm.ptr -> i64
      %75 = arith.constant 1 : i32
      %77 = arith.extsi %75 : i32 to i64
      %76 = arith.subi %74, %77 : i64
      %78 = llvm.getelementptr %73[%76] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %72 = llvm.load %78 : !llvm.ptr -> i64
      %79 = llvm.load %68 : !llvm.ptr -> i64
      %71 = func.call @modmul(%72, %79) : (i64, i64) -> i64
      %80 = llvm.load %50 : !llvm.ptr -> !llvm.ptr
      %81 = llvm.load %68 : !llvm.ptr -> i64
      %82 = llvm.getelementptr %80[%81] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %71, %82 : i64, !llvm.ptr
      %83 = llvm.load %68 : !llvm.ptr -> i64
      %84 = arith.constant 1 : i32
      %86 = arith.extsi %84 : i32 to i64
      %85 = arith.addi %83, %86 : i64
      llvm.store %85, %68 : i64, !llvm.ptr
      cf.br ^bb6
    ^bb8:
    %89 = llvm.load %50 : !llvm.ptr -> !llvm.ptr
    %90 = llvm.getelementptr %89[%arg0] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %88 = llvm.load %90 : !llvm.ptr -> i64
    %91 = llvm.mlir.addressof @MOD : !llvm.ptr
    %92 = llvm.load %91 : !llvm.ptr -> i64
    %93 = arith.constant 2 : i32
    %95 = arith.extsi %93 : i32 to i64
    %94 = arith.subi %92, %95 : i64
    %87 = func.call @modpow(%88, %94) : (i64, i64) -> i64
    %96 = llvm.load %58 : !llvm.ptr -> !llvm.ptr
    %97 = llvm.getelementptr %96[%arg0] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %87, %97 : i64, !llvm.ptr
    llvm.store %arg0, %68 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %98 = llvm.load %68 : !llvm.ptr -> i64
    %99 = arith.constant 0 : i32
    %101 = arith.extsi %99 : i32 to i64
    %100 = arith.cmpi sgt, %98, %101 : i64
    cf.cond_br %100, ^bb10, ^bb11
    ^bb10:
      %104 = llvm.load %58 : !llvm.ptr -> !llvm.ptr
      %105 = llvm.load %68 : !llvm.ptr -> i64
      %106 = llvm.getelementptr %104[%105] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %103 = llvm.load %106 : !llvm.ptr -> i64
      %107 = llvm.load %68 : !llvm.ptr -> i64
      %102 = func.call @modmul(%103, %107) : (i64, i64) -> i64
      %108 = llvm.load %58 : !llvm.ptr -> !llvm.ptr
      %109 = llvm.load %68 : !llvm.ptr -> i64
      %110 = arith.constant 1 : i32
      %112 = arith.extsi %110 : i32 to i64
      %111 = arith.subi %109, %112 : i64
      %113 = llvm.getelementptr %108[%111] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %102, %113 : i64, !llvm.ptr
      %114 = llvm.load %68 : !llvm.ptr -> i64
      %115 = arith.constant 1 : i32
      %117 = arith.extsi %115 : i32 to i64
      %116 = arith.subi %114, %117 : i64
      llvm.store %116, %68 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %118 = arith.constant 0 : i32
    %119 = arith.extsi %118 : i32 to i64
    %120 = llvm.mlir.constant(1 : i64) : i64
    %121 = llvm.alloca %120 x i64 : (i64) -> !llvm.ptr
    llvm.store %119, %121 : i64, !llvm.ptr
    %122 = llvm.mlir.addressof @MOD : !llvm.ptr
    %123 = llvm.load %122 : !llvm.ptr -> i64
    %124 = arith.constant 1 : i32
    %126 = arith.extsi %124 : i32 to i64
    %125 = arith.addi %123, %126 : i64
    %127 = arith.constant 2 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.divsi %125, %129 : i64
    %130 = arith.constant 1 : i32
    %131 = arith.extsi %130 : i32 to i64
    %132 = llvm.mlir.constant(1 : i64) : i64
    %133 = llvm.alloca %132 x i64 : (i64) -> !llvm.ptr
    llvm.store %131, %133 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %134 = llvm.load %133 : !llvm.ptr -> i64
    %135 = arith.constant 2 : i32
    %137 = arith.extsi %135 : i32 to i64
    %136 = arith.divsi %arg0, %137 : i64
    %138 = arith.cmpi sle, %134, %136 : i64
    cf.cond_br %138, ^bb13, ^bb14
    ^bb13:
      %139 = arith.constant 1 : i32
      %140 = arith.extsi %139 : i32 to i64
      %141 = llvm.mlir.constant(1 : i64) : i64
      %142 = llvm.alloca %141 x i64 : (i64) -> !llvm.ptr
      llvm.store %140, %142 : i64, !llvm.ptr
      %143 = llvm.load %133 : !llvm.ptr -> i64
      %144 = arith.constant 1 : i32
      %146 = arith.extsi %144 : i32 to i64
      %145 = arith.cmpi sgt, %143, %146 : i64
      cf.cond_br %145, ^bb15, ^bb16
      ^bb15:
        %148 = llvm.load %133 : !llvm.ptr -> i64
        %149 = llvm.load %133 : !llvm.ptr -> i64
        %150 = arith.constant 2 : i32
        %152 = arith.extsi %150 : i32 to i64
        %151 = arith.subi %149, %152 : i64
        %147 = func.call @modpow(%148, %151) : (i64, i64) -> i64
        llvm.store %147, %142 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %154 = llvm.load %133 : !llvm.ptr -> i64
      %155 = arith.subi %arg0, %154 : i64
      %156 = llvm.load %133 : !llvm.ptr -> i64
      %157 = arith.subi %arg0, %156 : i64
      %158 = arith.constant 2 : i32
      %160 = arith.extsi %158 : i32 to i64
      %159 = arith.subi %157, %160 : i64
      %153 = func.call @modpow(%155, %159) : (i64, i64) -> i64
      %163 = llvm.load %50 : !llvm.ptr -> !llvm.ptr
      %164 = llvm.getelementptr %163[%arg0] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %162 = llvm.load %164 : !llvm.ptr -> i64
      %167 = llvm.load %58 : !llvm.ptr -> !llvm.ptr
      %168 = llvm.load %133 : !llvm.ptr -> i64
      %169 = llvm.getelementptr %167[%168] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %166 = llvm.load %169 : !llvm.ptr -> i64
      %171 = llvm.load %58 : !llvm.ptr -> !llvm.ptr
      %172 = llvm.load %133 : !llvm.ptr -> i64
      %173 = arith.subi %arg0, %172 : i64
      %174 = llvm.getelementptr %171[%173] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %170 = llvm.load %174 : !llvm.ptr -> i64
      %165 = func.call @modmul(%166, %170) : (i64, i64) -> i64
      %161 = func.call @modmul(%162, %165) : (i64, i64) -> i64
      %175 = llvm.mlir.constant(1 : i64) : i64
      %176 = llvm.alloca %175 x i64 : (i64) -> !llvm.ptr
      llvm.store %161, %176 : i64, !llvm.ptr
      %178 = llvm.load %176 : !llvm.ptr -> i64
      %179 = llvm.load %142 : !llvm.ptr -> i64
      %177 = func.call @modmul(%178, %179) : (i64, i64) -> i64
      llvm.store %177, %176 : i64, !llvm.ptr
      %181 = llvm.load %176 : !llvm.ptr -> i64
      %180 = func.call @modmul(%181, %153) : (i64, i64) -> i64
      llvm.store %180, %176 : i64, !llvm.ptr
      %183 = llvm.load %176 : !llvm.ptr -> i64
      %184 = llvm.load %133 : !llvm.ptr -> i64
      %182 = func.call @modmul(%183, %184) : (i64, i64) -> i64
      llvm.store %182, %176 : i64, !llvm.ptr
      %186 = llvm.load %176 : !llvm.ptr -> i64
      %187 = llvm.load %133 : !llvm.ptr -> i64
      %188 = arith.subi %arg0, %187 : i64
      %185 = func.call @modmul(%186, %188) : (i64, i64) -> i64
      llvm.store %185, %176 : i64, !llvm.ptr
      %189 = arith.constant 2 : i32
      %190 = llvm.load %133 : !llvm.ptr -> i64
      %192 = arith.extsi %189 : i32 to i64
      %191 = arith.muli %192, %190 : i64
      %193 = arith.cmpi eq, %191, %arg0 : i64
      cf.cond_br %193, ^bb18, ^bb19
      ^bb18:
        %195 = llvm.load %176 : !llvm.ptr -> i64
        %194 = func.call @modmul(%195, %128) : (i64, i64) -> i64
        llvm.store %194, %176 : i64, !llvm.ptr
        cf.br ^bb20
      ^bb19:
        cf.br ^bb20
      ^bb20:
      %196 = llvm.load %121 : !llvm.ptr -> i64
      %198 = llvm.load %133 : !llvm.ptr -> i64
      %199 = llvm.load %176 : !llvm.ptr -> i64
      %197 = func.call @modmul(%198, %199) : (i64, i64) -> i64
      %200 = arith.addi %196, %197 : i64
      %201 = llvm.mlir.addressof @MOD : !llvm.ptr
      %202 = llvm.load %201 : !llvm.ptr -> i64
      %203 = arith.remsi %200, %202 : i64
      llvm.store %203, %121 : i64, !llvm.ptr
      %204 = llvm.load %133 : !llvm.ptr -> i64
      %205 = arith.constant 1 : i32
      %207 = arith.extsi %205 : i32 to i64
      %206 = arith.addi %204, %207 : i64
      llvm.store %206, %133 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %209 = llvm.load %121 : !llvm.ptr -> i64
    %211 = llvm.load %50 : !llvm.ptr -> !llvm.ptr
    %212 = arith.constant 1 : i32
    %214 = arith.extsi %212 : i32 to i64
    %213 = arith.subi %arg0, %214 : i64
    %215 = llvm.getelementptr %211[%213] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %210 = llvm.load %215 : !llvm.ptr -> i64
    %208 = func.call @modmul(%209, %210) : (i64, i64) -> i64
    %217 = llvm.load %50 : !llvm.ptr -> !llvm.ptr
    func.call @free(%217) : (!llvm.ptr) -> ()
    %219 = llvm.load %58 : !llvm.ptr -> !llvm.ptr
    func.call @free(%219) : (!llvm.ptr) -> ()
    func.return %208 : i64
  }
  func.func @main() -> i32 {
    %220 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %222 = arith.constant 100 : i32
    %223 = arith.extsi %222 : i32 to i64
    %221 = func.call @F(%223) : (i64) -> i64
    %224 = llvm.call @printf(%220, %221) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %225 = arith.constant 0 : i32
    func.return %225 : i32
  }
}