Problem 650

Divisors of binomial product: track sigma(B_n) mod 1e9+7 up to n=20000.

Answer538319652
Output538319652
StatusPASS
Native helperno
Runtime1630 ms
Peak memory1472 KB
Time complexityO(n^3) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^3)O(n log log n)
Space complexityO(n^2)O(n)
ApproachFlow solutionSieve-based divisor sums
VerdictSuboptimal

Flow source

# Project Euler 650
# Divisors of binomial product: track sigma(B_n) mod 1e9+7 up to n=20000.

import euler.nt { mod_pow }

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

const LIMIT: i32 = 20000
const MOD: i64 = 1000000007

function main() -> i32 {
    let spf: ptr<i32> = calloc((LIMIT + 1) as i64, 4)
    let primes: ptr<i32> = calloc(LIMIT as i64, 4)
    let mut pc: i32 = 0

    # Linear sieve
    let mut x: i32 = 2
    while x <= LIMIT {
        if spf[x] == 0 {
            spf[x] = x
            primes[pc] = x
            pc = pc + 1
        }
        let mut j: i32 = 0
        while j < pc {
            let y: i64 = (primes[j] as i64) * (x as i64)
            if y > (LIMIT as i64) { break }
            spf[y as i32] = primes[j]
            if primes[j] == spf[x] { break }
            j = j + 1
        }
        x = x + 1
    }

    let pidx: ptr<i32> = calloc((LIMIT + 1) as i64, 4)
    let mut i: i32 = 0
    while i < pc {
        pidx[primes[i]] = i
        i = i + 1
    }

    let prime_power: ptr<i64> = calloc(pc as i64, 8)
    let inv_fact: ptr<i64> = calloc(pc as i64, 8)
    let inv_prime: ptr<i64> = calloc(pc as i64, 8)
    let sigma_den: ptr<i64> = calloc(pc as i64, 8)

    let mut k: i32 = 0
    while k < pc {
        prime_power[k] = (primes[k] as i64) % MOD
        inv_fact[k] = 1
        inv_prime[k] = mod_pow(primes[k] as i64, MOD - 2, MOD)
        sigma_den[k] = mod_pow((primes[k] as i64) - 1, MOD - 2, MOD)
        k = k + 1
    }

    let mut active: i32 = 0
    let mut total: i64 = 1

    let mut n: i32 = 2
    while n <= LIMIT {
        while active < pc && primes[active] <= n {
            active = active + 1
        }

        # Divide each active prime_power by its current factorial exponent
        let mut a: i32 = 0
        while a < active {
            prime_power[a] = ((prime_power[a] as i128) * inv_fact[a] % MOD) as i64
            a = a + 1
        }

        # Factor n and update prime_power and inv_fact
        let mut xf: i32 = n
        while xf > 1 {
            let p: i32 = spf[xf]
            let mut e: i32 = 0
            while xf % p == 0 {
                xf = xf / p
                e = e + 1
            }
            let idx: i32 = pidx[p]
            let pe: i64 = mod_pow(p as i64, ((n - 1) as i64) * (e as i64), MOD)
            prime_power[idx] = ((prime_power[idx] as i128) * pe % MOD) as i64
            let ipow: i64 = mod_pow(inv_prime[idx], e as i64, MOD)
            inv_fact[idx] = ((inv_fact[idx] as i128) * ipow % MOD) as i64
        }

        # Compute divisor sum = product of (prime_power[i] - 1) / (prime[i] - 1)
        let mut divisor_sum: i64 = 1
        let mut b: i32 = 0
        while b < active {
            let mut t: i64 = (prime_power[b] - 1) % MOD
            if t < 0 { t = t + MOD }
            divisor_sum = ((divisor_sum as i128) * t % MOD * sigma_den[b] % MOD) as i64
            b = b + 1
        }

        total = (total + divisor_sum) % MOD
        n = n + 1
    }

    printf("%lld\n", total)

    free(spf)
    free(primes)
    free(pidx)
    free(prime_power)
    free(inv_fact)
    free(inv_prime)
    free(sigma_den)
    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 gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
int32_t main(void);

static const int32_t LIMIT = 20000;
static const int64_t MOD = 1000000007;

int64_t gcd_i64_i64(int64_t a0, int64_t b0) {
    int64_t a = a0;
    int64_t b = b0;
    while (b != 0) {
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    return a;
}

int64_t lcm_i64_i64(int64_t a, int64_t b) {
    if ((a == 0 || b == 0)) {
        return 0;
    }
    return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}

int64_t isqrt_i64(int64_t n) {
    if (n < 2) {
        return n;
    }
    int64_t x = n;
    int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
    while (y < x) {
        x = y;
        y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
    }
    return x;
}

int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
    int64_t a = FLOW_CHECKED_MOD((a0), (mod));
    int64_t b = FLOW_CHECKED_MOD((b0), (mod));
    int64_t result = 0;
    while (b > 0) {
        if (FLOW_CHECKED_MOD((b), (2)) == 1) {
            result = FLOW_CHECKED_MOD(((result + a)), (mod));
        }
        a = FLOW_CHECKED_MOD(((a * 2)), (mod));
        b = FLOW_CHECKED_DIV((b), (2));
    }
    return result;
}

int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
    if (mod == 1) {
        return 0;
    }
    int64_t result = 1;
    int64_t b = FLOW_CHECKED_MOD((base), (mod));
    int64_t e = exp;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            result = mulmod_i64_i64_i64(result, b, mod);
        }
        b = mulmod_i64_i64_i64(b, b, mod);
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return result;
}

bool is_prime_i64(int64_t n) {
    if (n < 2) {
        return 0;
    }
    if (n < 4) {
        return 1;
    }
    if ((FLOW_CHECKED_MOD((n), (2)) == 0 || FLOW_CHECKED_MOD((n), (3)) == 0)) {
        return 0;
    }
    int64_t i = 5;
    while ((i * i) <= n) {
        if ((FLOW_CHECKED_MOD((n), (i)) == 0 || FLOW_CHECKED_MOD((n), ((i + 2))) == 0)) {
            return 0;
        }
        i = (i + 6);
    }
    return 1;
}



int32_t main(void) {
    int32_t* spf = (int32_t*)(calloc(((int64_t)((LIMIT + 1))), 4));
    int32_t* primes = (int32_t*)(calloc(((int64_t)(LIMIT)), 4));
    int32_t pc = 0;
    int32_t x = 2;
    while (x <= LIMIT) {
        if (spf[x] == 0) {
            spf[x] = x;
            primes[pc] = x;
            pc = (pc + 1);
        }
        int32_t j = 0;
        while (j < pc) {
            int64_t y = (((int64_t)(primes[j])) * ((int64_t)(x)));
            if (y > ((int64_t)(LIMIT))) {
                break;
            }
            spf[((int32_t)(y))] = primes[j];
            if (primes[j] == spf[x]) {
                break;
            }
            j = (j + 1);
        }
        x = (x + 1);
    }
    int32_t* pidx = (int32_t*)(calloc(((int64_t)((LIMIT + 1))), 4));
    int32_t i = 0;
    while (i < pc) {
        pidx[primes[i]] = i;
        i = (i + 1);
    }
    int64_t* prime_power = (int64_t*)(calloc(((int64_t)(pc)), 8));
    int64_t* inv_fact = (int64_t*)(calloc(((int64_t)(pc)), 8));
    int64_t* inv_prime = (int64_t*)(calloc(((int64_t)(pc)), 8));
    int64_t* sigma_den = (int64_t*)(calloc(((int64_t)(pc)), 8));
    int32_t k = 0;
    while (k < pc) {
        prime_power[k] = FLOW_CHECKED_MOD((((int64_t)(primes[k]))), (MOD));
        inv_fact[k] = 1;
        inv_prime[k] = mod_pow_i64_i64_i64(((int64_t)(primes[k])), (MOD - 2), MOD);
        sigma_den[k] = mod_pow_i64_i64_i64((((int64_t)(primes[k])) - 1), (MOD - 2), MOD);
        k = (k + 1);
    }
    int32_t active = 0;
    int64_t total = 1;
    int32_t n = 2;
    while (n <= LIMIT) {
        while ((active < pc && primes[active] <= n)) {
            active = (active + 1);
        }
        int32_t a = 0;
        while (a < active) {
            prime_power[a] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(prime_power[a])) * inv_fact[a])), (MOD))));
            a = (a + 1);
        }
        int32_t xf = n;
        while (xf > 1) {
            int32_t p = spf[xf];
            int32_t e = 0;
            while (FLOW_CHECKED_MOD((xf), (p)) == 0) {
                xf = FLOW_CHECKED_DIV((xf), (p));
                e = (e + 1);
            }
            int32_t idx = pidx[p];
            int64_t pe = mod_pow_i64_i64_i64(((int64_t)(p)), (((int64_t)((n - 1))) * ((int64_t)(e))), MOD);
            prime_power[idx] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(prime_power[idx])) * pe)), (MOD))));
            int64_t ipow = mod_pow_i64_i64_i64(inv_prime[idx], ((int64_t)(e)), MOD);
            inv_fact[idx] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(inv_fact[idx])) * ipow)), (MOD))));
        }
        int64_t divisor_sum = 1;
        int32_t b = 0;
        while (b < active) {
            int64_t t = FLOW_CHECKED_MOD(((prime_power[b] - 1)), (MOD));
            if (t < 0) {
                t = (t + MOD);
            }
            divisor_sum = ((int64_t)(FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((((__int128)(divisor_sum)) * t)), (MOD)) * sigma_den[b])), (MOD))));
            b = (b + 1);
        }
        total = FLOW_CHECKED_MOD(((total + divisor_sum)), (MOD));
        n = (n + 1);
    }
    printf("%lld\n", total);
    free(spf);
    free(primes);
    free(pidx);
    free(prime_power);
    free(inv_fact);
    free(inv_prime);
    free(sigma_den);
    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 @gcd(%arg0: i64, %arg1: i64) -> i64 {
    %0 = llvm.mlir.constant(1 : i64) : i64
    %1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %1 : i64, !llvm.ptr
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %3 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %4 = llvm.load %3 : !llvm.ptr -> i64
    %5 = arith.constant 0 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.cmpi ne, %4, %7 : i64
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %8 = llvm.load %1 : !llvm.ptr -> i64
      %9 = llvm.load %3 : !llvm.ptr -> i64
      %10 = arith.remsi %8, %9 : i64
      %11 = llvm.load %3 : !llvm.ptr -> i64
      llvm.store %11, %1 : i64, !llvm.ptr
      llvm.store %10, %3 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %12 = llvm.load %1 : !llvm.ptr -> i64
    func.return %12 : i64
  }
  func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
    %13 = arith.constant 0 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.cmpi eq, %arg0, %15 : i64
    %16 = scf.if %14 -> (i1) {
      %17 = arith.constant true
      scf.yield %17 : i1
    } else {
      %18 = arith.constant 0 : i32
      %20 = arith.extsi %18 : i32 to i64
      %19 = arith.cmpi eq, %arg1, %20 : i64
      scf.yield %19 : i1
    }
    cf.cond_br %16, ^bb3, ^bb4
    ^bb3:
      %21 = arith.constant 0 : i32
      %22 = arith.extsi %21 : i32 to i64
      func.return %22 : i64
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
    %24 = arith.divsi %arg0, %23 : i64
    %25 = arith.muli %24, %arg1 : i64
    func.return %25 : i64
  }
  func.func @isqrt(%arg0: i64) -> i64 {
    %26 = arith.constant 2 : i32
    %28 = arith.extsi %26 : i32 to i64
    %27 = arith.cmpi slt, %arg0, %28 : i64
    cf.cond_br %27, ^bb6, ^bb7
    ^bb6:
      func.return %arg0 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %29 = llvm.mlir.constant(1 : i64) : i64
    %30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %30 : i64, !llvm.ptr
    %31 = llvm.load %30 : !llvm.ptr -> i64
    %32 = arith.constant 1 : i32
    %34 = arith.extsi %32 : i32 to i64
    %33 = arith.addi %31, %34 : i64
    %35 = arith.constant 2 : i32
    %37 = arith.extsi %35 : i32 to i64
    %36 = arith.divsi %33, %37 : i64
    %38 = llvm.mlir.constant(1 : i64) : i64
    %39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
    llvm.store %36, %39 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %40 = llvm.load %39 : !llvm.ptr -> i64
    %41 = llvm.load %30 : !llvm.ptr -> i64
    %42 = arith.cmpi slt, %40, %41 : i64
    cf.cond_br %42, ^bb10, ^bb11
    ^bb10:
      %43 = llvm.load %39 : !llvm.ptr -> i64
      llvm.store %43, %30 : i64, !llvm.ptr
      %44 = llvm.load %30 : !llvm.ptr -> i64
      %45 = llvm.load %30 : !llvm.ptr -> i64
      %46 = arith.divsi %arg0, %45 : i64
      %47 = arith.addi %44, %46 : i64
      %48 = arith.constant 2 : i32
      %50 = arith.extsi %48 : i32 to i64
      %49 = arith.divsi %47, %50 : i64
      llvm.store %49, %39 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %51 = llvm.load %30 : !llvm.ptr -> i64
    func.return %51 : i64
  }
  func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %52 = arith.remsi %arg0, %arg2 : i64
    %53 = llvm.mlir.constant(1 : i64) : i64
    %54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
    llvm.store %52, %54 : i64, !llvm.ptr
    %55 = arith.remsi %arg1, %arg2 : i64
    %56 = llvm.mlir.constant(1 : i64) : i64
    %57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
    llvm.store %55, %57 : i64, !llvm.ptr
    %58 = arith.constant 0 : i32
    %59 = arith.extsi %58 : i32 to i64
    %60 = llvm.mlir.constant(1 : i64) : i64
    %61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
    llvm.store %59, %61 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %62 = llvm.load %57 : !llvm.ptr -> i64
    %63 = arith.constant 0 : i32
    %65 = arith.extsi %63 : i32 to i64
    %64 = arith.cmpi sgt, %62, %65 : i64
    cf.cond_br %64, ^bb13, ^bb14
    ^bb13:
      %66 = llvm.load %57 : !llvm.ptr -> i64
      %67 = arith.constant 2 : i32
      %69 = arith.extsi %67 : i32 to i64
      %68 = arith.remsi %66, %69 : i64
      %70 = arith.constant 1 : i32
      %72 = arith.extsi %70 : i32 to i64
      %71 = arith.cmpi eq, %68, %72 : i64
      cf.cond_br %71, ^bb15, ^bb16
      ^bb15:
        %73 = llvm.load %61 : !llvm.ptr -> i64
        %74 = llvm.load %54 : !llvm.ptr -> i64
        %75 = arith.addi %73, %74 : i64
        %76 = arith.remsi %75, %arg2 : i64
        llvm.store %76, %61 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %77 = llvm.load %54 : !llvm.ptr -> i64
      %78 = arith.constant 2 : i32
      %80 = arith.extsi %78 : i32 to i64
      %79 = arith.muli %77, %80 : i64
      %81 = arith.remsi %79, %arg2 : i64
      llvm.store %81, %54 : i64, !llvm.ptr
      %82 = llvm.load %57 : !llvm.ptr -> i64
      %83 = arith.constant 2 : i32
      %85 = arith.extsi %83 : i32 to i64
      %84 = arith.divsi %82, %85 : i64
      llvm.store %84, %57 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %86 = llvm.load %61 : !llvm.ptr -> i64
    func.return %86 : i64
  }
  func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %87 = arith.constant 1 : i32
    %89 = arith.extsi %87 : i32 to i64
    %88 = arith.cmpi eq, %arg2, %89 : i64
    cf.cond_br %88, ^bb18, ^bb19
    ^bb18:
      %90 = arith.constant 0 : i32
      %91 = arith.extsi %90 : i32 to i64
      func.return %91 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %92 = arith.constant 1 : i32
    %93 = arith.extsi %92 : i32 to i64
    %94 = llvm.mlir.constant(1 : i64) : i64
    %95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
    llvm.store %93, %95 : i64, !llvm.ptr
    %96 = arith.remsi %arg0, %arg2 : i64
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i64, !llvm.ptr
    %99 = llvm.mlir.constant(1 : i64) : i64
    %100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %100 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %101 = llvm.load %100 : !llvm.ptr -> i64
    %102 = arith.constant 0 : i32
    %104 = arith.extsi %102 : i32 to i64
    %103 = arith.cmpi sgt, %101, %104 : i64
    cf.cond_br %103, ^bb22, ^bb23
    ^bb22:
      %105 = llvm.load %100 : !llvm.ptr -> i64
      %106 = arith.constant 2 : i32
      %108 = arith.extsi %106 : i32 to i64
      %107 = arith.remsi %105, %108 : i64
      %109 = arith.constant 1 : i32
      %111 = arith.extsi %109 : i32 to i64
      %110 = arith.cmpi eq, %107, %111 : i64
      cf.cond_br %110, ^bb24, ^bb25
      ^bb24:
        %113 = llvm.load %95 : !llvm.ptr -> i64
        %114 = llvm.load %98 : !llvm.ptr -> i64
        %112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
        llvm.store %112, %95 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %116 = llvm.load %98 : !llvm.ptr -> i64
      %117 = llvm.load %98 : !llvm.ptr -> i64
      %115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
      llvm.store %115, %98 : i64, !llvm.ptr
      %118 = llvm.load %100 : !llvm.ptr -> i64
      %119 = arith.constant 2 : i32
      %121 = arith.extsi %119 : i32 to i64
      %120 = arith.divsi %118, %121 : i64
      llvm.store %120, %100 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %122 = llvm.load %95 : !llvm.ptr -> i64
    func.return %122 : i64
  }
  func.func @is_prime(%arg0: i64) -> i1 {
    %123 = arith.constant 2 : i32
    %125 = arith.extsi %123 : i32 to i64
    %124 = arith.cmpi slt, %arg0, %125 : i64
    cf.cond_br %124, ^bb27, ^bb28
    ^bb27:
      %126 = arith.constant 0 : i1
      func.return %126 : i1
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %127 = arith.constant 4 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.cmpi slt, %arg0, %129 : i64
    cf.cond_br %128, ^bb30, ^bb31
    ^bb30:
      %130 = arith.constant 1 : i1
      func.return %130 : i1
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %131 = arith.constant 2 : i32
    %133 = arith.extsi %131 : i32 to i64
    %132 = arith.remsi %arg0, %133 : i64
    %134 = arith.constant 0 : i32
    %136 = arith.extsi %134 : i32 to i64
    %135 = arith.cmpi eq, %132, %136 : i64
    %137 = scf.if %135 -> (i1) {
      %138 = arith.constant true
      scf.yield %138 : i1
    } else {
      %139 = arith.constant 3 : i32
      %141 = arith.extsi %139 : i32 to i64
      %140 = arith.remsi %arg0, %141 : i64
      %142 = arith.constant 0 : i32
      %144 = arith.extsi %142 : i32 to i64
      %143 = arith.cmpi eq, %140, %144 : i64
      scf.yield %143 : i1
    }
    cf.cond_br %137, ^bb33, ^bb34
    ^bb33:
      %145 = arith.constant 0 : i1
      func.return %145 : i1
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %146 = arith.constant 5 : i32
    %147 = arith.extsi %146 : i32 to i64
    %148 = llvm.mlir.constant(1 : i64) : i64
    %149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
    llvm.store %147, %149 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %150 = llvm.load %149 : !llvm.ptr -> i64
    %151 = llvm.load %149 : !llvm.ptr -> i64
    %152 = arith.muli %150, %151 : i64
    %153 = arith.cmpi sle, %152, %arg0 : i64
    cf.cond_br %153, ^bb37, ^bb38
    ^bb37:
      %154 = llvm.load %149 : !llvm.ptr -> i64
      %155 = arith.remsi %arg0, %154 : i64
      %156 = arith.constant 0 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.cmpi eq, %155, %158 : i64
      %159 = scf.if %157 -> (i1) {
        %160 = arith.constant true
        scf.yield %160 : i1
      } else {
        %161 = llvm.load %149 : !llvm.ptr -> i64
        %162 = arith.constant 2 : i32
        %164 = arith.extsi %162 : i32 to i64
        %163 = arith.addi %161, %164 : i64
        %165 = arith.remsi %arg0, %163 : i64
        %166 = arith.constant 0 : i32
        %168 = arith.extsi %166 : i32 to i64
        %167 = arith.cmpi eq, %165, %168 : i64
        scf.yield %167 : i1
      }
      cf.cond_br %159, ^bb39, ^bb40
      ^bb39:
        %169 = arith.constant 0 : i1
        func.return %169 : i1
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %170 = llvm.load %149 : !llvm.ptr -> i64
      %171 = arith.constant 6 : i32
      %173 = arith.extsi %171 : i32 to i64
      %172 = arith.addi %170, %173 : i64
      llvm.store %172, %149 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %174 = arith.constant 1 : i1
    func.return %174 : i1
  }
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  // Constant: LIMIT
  llvm.mlir.global internal constant @LIMIT(20000 : i32) : i32
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
  func.func @main() -> i32 {
    %176 = llvm.mlir.addressof @LIMIT : !llvm.ptr
    %177 = llvm.load %176 : !llvm.ptr -> i32
    %178 = arith.constant 1 : i32
    %179 = arith.addi %177, %178 : i32
    %180 = arith.extsi %179 : i32 to i64
    %181 = arith.constant 4 : i32
    %182 = arith.extsi %181 : i32 to i64
    %175 = func.call @calloc(%180, %182) : (i64, i64) -> !llvm.ptr
    %184 = llvm.mlir.addressof @LIMIT : !llvm.ptr
    %185 = llvm.load %184 : !llvm.ptr -> i32
    %186 = arith.extsi %185 : i32 to i64
    %187 = arith.constant 4 : i32
    %188 = arith.extsi %187 : i32 to i64
    %183 = func.call @calloc(%186, %188) : (i64, i64) -> !llvm.ptr
    %189 = arith.constant 0 : i32
    %190 = llvm.mlir.constant(1 : i64) : i64
    %191 = llvm.alloca %190 x i32 : (i64) -> !llvm.ptr
    llvm.store %189, %191 : i32, !llvm.ptr
    %192 = arith.constant 2 : i32
    %193 = llvm.mlir.constant(1 : i64) : i64
    %194 = llvm.alloca %193 x i32 : (i64) -> !llvm.ptr
    llvm.store %192, %194 : i32, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %195 = llvm.load %194 : !llvm.ptr -> i32
    %196 = llvm.mlir.addressof @LIMIT : !llvm.ptr
    %197 = llvm.load %196 : !llvm.ptr -> i32
    %198 = arith.cmpi sle, %195, %197 : i32
    cf.cond_br %198, ^bb43, ^bb44
    ^bb43:
      %200 = llvm.load %194 : !llvm.ptr -> i32
      %201 = arith.extsi %200 : i32 to i64
      %202 = llvm.getelementptr %175[%201] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %199 = llvm.load %202 : !llvm.ptr -> i32
      %203 = arith.constant 0 : i32
      %204 = arith.cmpi eq, %199, %203 : i32
      cf.cond_br %204, ^bb45, ^bb46
      ^bb45:
        %205 = llvm.load %194 : !llvm.ptr -> i32
        %206 = llvm.load %194 : !llvm.ptr -> i32
        %207 = arith.extsi %206 : i32 to i64
        %208 = llvm.getelementptr %175[%207] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %205, %208 : i32, !llvm.ptr
        %209 = llvm.load %194 : !llvm.ptr -> i32
        %210 = llvm.load %191 : !llvm.ptr -> i32
        %211 = arith.extsi %210 : i32 to i64
        %212 = llvm.getelementptr %183[%211] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %209, %212 : i32, !llvm.ptr
        %213 = llvm.load %191 : !llvm.ptr -> i32
        %214 = arith.constant 1 : i32
        %215 = arith.addi %213, %214 : i32
        llvm.store %215, %191 : i32, !llvm.ptr
        cf.br ^bb47
      ^bb46:
        cf.br ^bb47
      ^bb47:
      %216 = arith.constant 0 : i32
      %217 = llvm.mlir.constant(1 : i64) : i64
      %218 = llvm.alloca %217 x i32 : (i64) -> !llvm.ptr
      llvm.store %216, %218 : i32, !llvm.ptr
      cf.br ^bb48
      ^bb48:
      %219 = llvm.load %218 : !llvm.ptr -> i32
      %220 = llvm.load %191 : !llvm.ptr -> i32
      %221 = arith.cmpi slt, %219, %220 : i32
      cf.cond_br %221, ^bb49, ^bb50
      ^bb49:
        %223 = llvm.load %218 : !llvm.ptr -> i32
        %224 = arith.extsi %223 : i32 to i64
        %225 = llvm.getelementptr %183[%224] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %222 = llvm.load %225 : !llvm.ptr -> i32
        %226 = arith.extsi %222 : i32 to i64
        %227 = llvm.load %194 : !llvm.ptr -> i32
        %228 = arith.extsi %227 : i32 to i64
        %229 = arith.muli %226, %228 : i64
        %230 = llvm.mlir.addressof @LIMIT : !llvm.ptr
        %231 = llvm.load %230 : !llvm.ptr -> i32
        %232 = arith.extsi %231 : i32 to i64
        %233 = arith.cmpi sgt, %229, %232 : i64
        cf.cond_br %233, ^bb51, ^bb52
        ^bb51:
          cf.br ^bb50
        ^bb52:
          cf.br ^bb53
        ^bb53:
        %235 = llvm.load %218 : !llvm.ptr -> i32
        %236 = arith.extsi %235 : i32 to i64
        %237 = llvm.getelementptr %183[%236] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %234 = llvm.load %237 : !llvm.ptr -> i32
        %238 = arith.trunci %229 : i64 to i32
        %239 = arith.extsi %238 : i32 to i64
        %240 = llvm.getelementptr %175[%239] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %234, %240 : i32, !llvm.ptr
        %242 = llvm.load %218 : !llvm.ptr -> i32
        %243 = arith.extsi %242 : i32 to i64
        %244 = llvm.getelementptr %183[%243] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %241 = llvm.load %244 : !llvm.ptr -> i32
        %246 = llvm.load %194 : !llvm.ptr -> i32
        %247 = arith.extsi %246 : i32 to i64
        %248 = llvm.getelementptr %175[%247] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %245 = llvm.load %248 : !llvm.ptr -> i32
        %249 = arith.cmpi eq, %241, %245 : i32
        cf.cond_br %249, ^bb54, ^bb55
        ^bb54:
          cf.br ^bb50
        ^bb55:
          cf.br ^bb56
        ^bb56:
        %250 = llvm.load %218 : !llvm.ptr -> i32
        %251 = arith.constant 1 : i32
        %252 = arith.addi %250, %251 : i32
        llvm.store %252, %218 : i32, !llvm.ptr
        cf.br ^bb48
      ^bb50:
      %253 = llvm.load %194 : !llvm.ptr -> i32
      %254 = arith.constant 1 : i32
      %255 = arith.addi %253, %254 : i32
      llvm.store %255, %194 : i32, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    %257 = llvm.mlir.addressof @LIMIT : !llvm.ptr
    %258 = llvm.load %257 : !llvm.ptr -> i32
    %259 = arith.constant 1 : i32
    %260 = arith.addi %258, %259 : i32
    %261 = arith.extsi %260 : i32 to i64
    %262 = arith.constant 4 : i32
    %263 = arith.extsi %262 : i32 to i64
    %256 = func.call @calloc(%261, %263) : (i64, i64) -> !llvm.ptr
    %264 = arith.constant 0 : i32
    %265 = llvm.mlir.constant(1 : i64) : i64
    %266 = llvm.alloca %265 x i32 : (i64) -> !llvm.ptr
    llvm.store %264, %266 : i32, !llvm.ptr
    cf.br ^bb57
    ^bb57:
    %267 = llvm.load %266 : !llvm.ptr -> i32
    %268 = llvm.load %191 : !llvm.ptr -> i32
    %269 = arith.cmpi slt, %267, %268 : i32
    cf.cond_br %269, ^bb58, ^bb59
    ^bb58:
      %270 = llvm.load %266 : !llvm.ptr -> i32
      %272 = llvm.load %266 : !llvm.ptr -> i32
      %273 = arith.extsi %272 : i32 to i64
      %274 = llvm.getelementptr %183[%273] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %271 = llvm.load %274 : !llvm.ptr -> i32
      %275 = arith.extsi %271 : i32 to i64
      %276 = llvm.getelementptr %256[%275] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %270, %276 : i32, !llvm.ptr
      %277 = llvm.load %266 : !llvm.ptr -> i32
      %278 = arith.constant 1 : i32
      %279 = arith.addi %277, %278 : i32
      llvm.store %279, %266 : i32, !llvm.ptr
      cf.br ^bb57
    ^bb59:
    %281 = llvm.load %191 : !llvm.ptr -> i32
    %282 = arith.extsi %281 : i32 to i64
    %283 = arith.constant 8 : i32
    %284 = arith.extsi %283 : i32 to i64
    %280 = func.call @calloc(%282, %284) : (i64, i64) -> !llvm.ptr
    %286 = llvm.load %191 : !llvm.ptr -> i32
    %287 = arith.extsi %286 : i32 to i64
    %288 = arith.constant 8 : i32
    %289 = arith.extsi %288 : i32 to i64
    %285 = func.call @calloc(%287, %289) : (i64, i64) -> !llvm.ptr
    %291 = llvm.load %191 : !llvm.ptr -> i32
    %292 = arith.extsi %291 : i32 to i64
    %293 = arith.constant 8 : i32
    %294 = arith.extsi %293 : i32 to i64
    %290 = func.call @calloc(%292, %294) : (i64, i64) -> !llvm.ptr
    %296 = llvm.load %191 : !llvm.ptr -> i32
    %297 = arith.extsi %296 : i32 to i64
    %298 = arith.constant 8 : i32
    %299 = arith.extsi %298 : i32 to i64
    %295 = func.call @calloc(%297, %299) : (i64, i64) -> !llvm.ptr
    %300 = arith.constant 0 : i32
    %301 = llvm.mlir.constant(1 : i64) : i64
    %302 = llvm.alloca %301 x i32 : (i64) -> !llvm.ptr
    llvm.store %300, %302 : i32, !llvm.ptr
    cf.br ^bb60
    ^bb60:
    %303 = llvm.load %302 : !llvm.ptr -> i32
    %304 = llvm.load %191 : !llvm.ptr -> i32
    %305 = arith.cmpi slt, %303, %304 : i32
    cf.cond_br %305, ^bb61, ^bb62
    ^bb61:
      %307 = llvm.load %302 : !llvm.ptr -> i32
      %308 = arith.extsi %307 : i32 to i64
      %309 = llvm.getelementptr %183[%308] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %306 = llvm.load %309 : !llvm.ptr -> i32
      %310 = arith.extsi %306 : i32 to i64
      %311 = llvm.mlir.addressof @MOD : !llvm.ptr
      %312 = llvm.load %311 : !llvm.ptr -> i64
      %313 = arith.remsi %310, %312 : i64
      %314 = llvm.load %302 : !llvm.ptr -> i32
      %315 = arith.extsi %314 : i32 to i64
      %316 = llvm.getelementptr %280[%315] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %313, %316 : i64, !llvm.ptr
      %317 = arith.constant 1 : i32
      %318 = llvm.load %302 : !llvm.ptr -> i32
      %319 = arith.extsi %317 : i32 to i64
      %320 = arith.extsi %318 : i32 to i64
      %321 = llvm.getelementptr %285[%320] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %319, %321 : i64, !llvm.ptr
      %324 = llvm.load %302 : !llvm.ptr -> i32
      %325 = arith.extsi %324 : i32 to i64
      %326 = llvm.getelementptr %183[%325] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %323 = llvm.load %326 : !llvm.ptr -> i32
      %327 = arith.extsi %323 : i32 to i64
      %328 = llvm.mlir.addressof @MOD : !llvm.ptr
      %329 = llvm.load %328 : !llvm.ptr -> i64
      %330 = arith.constant 2 : i32
      %332 = arith.extsi %330 : i32 to i64
      %331 = arith.subi %329, %332 : i64
      %333 = llvm.mlir.addressof @MOD : !llvm.ptr
      %334 = llvm.load %333 : !llvm.ptr -> i64
      %322 = func.call @mod_pow(%327, %331, %334) : (i64, i64, i64) -> i64
      %335 = llvm.load %302 : !llvm.ptr -> i32
      %336 = arith.extsi %335 : i32 to i64
      %337 = llvm.getelementptr %290[%336] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %322, %337 : i64, !llvm.ptr
      %340 = llvm.load %302 : !llvm.ptr -> i32
      %341 = arith.extsi %340 : i32 to i64
      %342 = llvm.getelementptr %183[%341] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %339 = llvm.load %342 : !llvm.ptr -> i32
      %343 = arith.extsi %339 : i32 to i64
      %344 = arith.constant 1 : i32
      %346 = arith.extsi %344 : i32 to i64
      %345 = arith.subi %343, %346 : i64
      %347 = llvm.mlir.addressof @MOD : !llvm.ptr
      %348 = llvm.load %347 : !llvm.ptr -> i64
      %349 = arith.constant 2 : i32
      %351 = arith.extsi %349 : i32 to i64
      %350 = arith.subi %348, %351 : i64
      %352 = llvm.mlir.addressof @MOD : !llvm.ptr
      %353 = llvm.load %352 : !llvm.ptr -> i64
      %338 = func.call @mod_pow(%345, %350, %353) : (i64, i64, i64) -> i64
      %354 = llvm.load %302 : !llvm.ptr -> i32
      %355 = arith.extsi %354 : i32 to i64
      %356 = llvm.getelementptr %295[%355] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %338, %356 : i64, !llvm.ptr
      %357 = llvm.load %302 : !llvm.ptr -> i32
      %358 = arith.constant 1 : i32
      %359 = arith.addi %357, %358 : i32
      llvm.store %359, %302 : i32, !llvm.ptr
      cf.br ^bb60
    ^bb62:
    %360 = arith.constant 0 : i32
    %361 = llvm.mlir.constant(1 : i64) : i64
    %362 = llvm.alloca %361 x i32 : (i64) -> !llvm.ptr
    llvm.store %360, %362 : i32, !llvm.ptr
    %363 = arith.constant 1 : i32
    %364 = arith.extsi %363 : i32 to i64
    %365 = llvm.mlir.constant(1 : i64) : i64
    %366 = llvm.alloca %365 x i64 : (i64) -> !llvm.ptr
    llvm.store %364, %366 : i64, !llvm.ptr
    %367 = arith.constant 2 : i32
    %368 = llvm.mlir.constant(1 : i64) : i64
    %369 = llvm.alloca %368 x i32 : (i64) -> !llvm.ptr
    llvm.store %367, %369 : i32, !llvm.ptr
    cf.br ^bb63
    ^bb63:
    %370 = llvm.load %369 : !llvm.ptr -> i32
    %371 = llvm.mlir.addressof @LIMIT : !llvm.ptr
    %372 = llvm.load %371 : !llvm.ptr -> i32
    %373 = arith.cmpi sle, %370, %372 : i32
    cf.cond_br %373, ^bb64, ^bb65
    ^bb64:
      cf.br ^bb66
      ^bb66:
      %374 = llvm.load %362 : !llvm.ptr -> i32
      %375 = llvm.load %191 : !llvm.ptr -> i32
      %376 = arith.cmpi slt, %374, %375 : i32
      %377 = scf.if %376 -> (i1) {
        %379 = llvm.load %362 : !llvm.ptr -> i32
        %380 = arith.extsi %379 : i32 to i64
        %381 = llvm.getelementptr %183[%380] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %378 = llvm.load %381 : !llvm.ptr -> i32
        %382 = llvm.load %369 : !llvm.ptr -> i32
        %383 = arith.cmpi sle, %378, %382 : i32
        scf.yield %383 : i1
      } else {
        %384 = arith.constant false
        scf.yield %384 : i1
      }
      cf.cond_br %377, ^bb67, ^bb68
      ^bb67:
        %385 = llvm.load %362 : !llvm.ptr -> i32
        %386 = arith.constant 1 : i32
        %387 = arith.addi %385, %386 : i32
        llvm.store %387, %362 : i32, !llvm.ptr
        cf.br ^bb66
      ^bb68:
      %388 = arith.constant 0 : i32
      %389 = llvm.mlir.constant(1 : i64) : i64
      %390 = llvm.alloca %389 x i32 : (i64) -> !llvm.ptr
      llvm.store %388, %390 : i32, !llvm.ptr
      cf.br ^bb69
      ^bb69:
      %391 = llvm.load %390 : !llvm.ptr -> i32
      %392 = llvm.load %362 : !llvm.ptr -> i32
      %393 = arith.cmpi slt, %391, %392 : i32
      cf.cond_br %393, ^bb70, ^bb71
      ^bb70:
        %395 = llvm.load %390 : !llvm.ptr -> i32
        %396 = arith.extsi %395 : i32 to i64
        %397 = llvm.getelementptr %280[%396] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %394 = llvm.load %397 : !llvm.ptr -> i64
        %398 = arith.extsi %394 : i64 to i128
        %400 = llvm.load %390 : !llvm.ptr -> i32
        %401 = arith.extsi %400 : i32 to i64
        %402 = llvm.getelementptr %285[%401] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %399 = llvm.load %402 : !llvm.ptr -> i64
        %404 = arith.trunci %398 : i128 to i64
        %403 = arith.muli %404, %399 : i64
        %405 = llvm.mlir.addressof @MOD : !llvm.ptr
        %406 = llvm.load %405 : !llvm.ptr -> i64
        %407 = arith.remsi %403, %406 : i64
        %408 = llvm.load %390 : !llvm.ptr -> i32
        %409 = arith.extsi %408 : i32 to i64
        %410 = llvm.getelementptr %280[%409] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %407, %410 : i64, !llvm.ptr
        %411 = llvm.load %390 : !llvm.ptr -> i32
        %412 = arith.constant 1 : i32
        %413 = arith.addi %411, %412 : i32
        llvm.store %413, %390 : i32, !llvm.ptr
        cf.br ^bb69
      ^bb71:
      %414 = llvm.load %369 : !llvm.ptr -> i32
      %415 = llvm.mlir.constant(1 : i64) : i64
      %416 = llvm.alloca %415 x i32 : (i64) -> !llvm.ptr
      llvm.store %414, %416 : i32, !llvm.ptr
      cf.br ^bb72
      ^bb72:
      %417 = llvm.load %416 : !llvm.ptr -> i32
      %418 = arith.constant 1 : i32
      %419 = arith.cmpi sgt, %417, %418 : i32
      cf.cond_br %419, ^bb73, ^bb74
      ^bb73:
        %421 = llvm.load %416 : !llvm.ptr -> i32
        %422 = arith.extsi %421 : i32 to i64
        %423 = llvm.getelementptr %175[%422] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %420 = llvm.load %423 : !llvm.ptr -> i32
        %424 = arith.constant 0 : i32
        %425 = llvm.mlir.constant(1 : i64) : i64
        %426 = llvm.alloca %425 x i32 : (i64) -> !llvm.ptr
        llvm.store %424, %426 : i32, !llvm.ptr
        cf.br ^bb75
        ^bb75:
        %427 = llvm.load %416 : !llvm.ptr -> i32
        %428 = arith.remsi %427, %420 : i32
        %429 = arith.constant 0 : i32
        %430 = arith.cmpi eq, %428, %429 : i32
        cf.cond_br %430, ^bb76, ^bb77
        ^bb76:
          %431 = llvm.load %416 : !llvm.ptr -> i32
          %432 = arith.divsi %431, %420 : i32
          llvm.store %432, %416 : i32, !llvm.ptr
          %433 = llvm.load %426 : !llvm.ptr -> i32
          %434 = arith.constant 1 : i32
          %435 = arith.addi %433, %434 : i32
          llvm.store %435, %426 : i32, !llvm.ptr
          cf.br ^bb75
        ^bb77:
        %437 = arith.extsi %420 : i32 to i64
        %438 = llvm.getelementptr %256[%437] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %436 = llvm.load %438 : !llvm.ptr -> i32
        %440 = arith.extsi %420 : i32 to i64
        %441 = llvm.load %369 : !llvm.ptr -> i32
        %442 = arith.constant 1 : i32
        %443 = arith.subi %441, %442 : i32
        %444 = arith.extsi %443 : i32 to i64
        %445 = llvm.load %426 : !llvm.ptr -> i32
        %446 = arith.extsi %445 : i32 to i64
        %447 = arith.muli %444, %446 : i64
        %448 = llvm.mlir.addressof @MOD : !llvm.ptr
        %449 = llvm.load %448 : !llvm.ptr -> i64
        %439 = func.call @mod_pow(%440, %447, %449) : (i64, i64, i64) -> i64
        %451 = arith.extsi %436 : i32 to i64
        %452 = llvm.getelementptr %280[%451] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %450 = llvm.load %452 : !llvm.ptr -> i64
        %453 = arith.extsi %450 : i64 to i128
        %455 = arith.trunci %453 : i128 to i64
        %454 = arith.muli %455, %439 : i64
        %456 = llvm.mlir.addressof @MOD : !llvm.ptr
        %457 = llvm.load %456 : !llvm.ptr -> i64
        %458 = arith.remsi %454, %457 : i64
        %459 = arith.extsi %436 : i32 to i64
        %460 = llvm.getelementptr %280[%459] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %458, %460 : i64, !llvm.ptr
        %463 = arith.extsi %436 : i32 to i64
        %464 = llvm.getelementptr %290[%463] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %462 = llvm.load %464 : !llvm.ptr -> i64
        %465 = llvm.load %426 : !llvm.ptr -> i32
        %466 = arith.extsi %465 : i32 to i64
        %467 = llvm.mlir.addressof @MOD : !llvm.ptr
        %468 = llvm.load %467 : !llvm.ptr -> i64
        %461 = func.call @mod_pow(%462, %466, %468) : (i64, i64, i64) -> i64
        %470 = arith.extsi %436 : i32 to i64
        %471 = llvm.getelementptr %285[%470] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %469 = llvm.load %471 : !llvm.ptr -> i64
        %472 = arith.extsi %469 : i64 to i128
        %474 = arith.trunci %472 : i128 to i64
        %473 = arith.muli %474, %461 : i64
        %475 = llvm.mlir.addressof @MOD : !llvm.ptr
        %476 = llvm.load %475 : !llvm.ptr -> i64
        %477 = arith.remsi %473, %476 : i64
        %478 = arith.extsi %436 : i32 to i64
        %479 = llvm.getelementptr %285[%478] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %477, %479 : i64, !llvm.ptr
        cf.br ^bb72
      ^bb74:
      %480 = arith.constant 1 : i32
      %481 = arith.extsi %480 : i32 to i64
      %482 = llvm.mlir.constant(1 : i64) : i64
      %483 = llvm.alloca %482 x i64 : (i64) -> !llvm.ptr
      llvm.store %481, %483 : i64, !llvm.ptr
      %484 = arith.constant 0 : i32
      %485 = llvm.mlir.constant(1 : i64) : i64
      %486 = llvm.alloca %485 x i32 : (i64) -> !llvm.ptr
      llvm.store %484, %486 : i32, !llvm.ptr
      cf.br ^bb78
      ^bb78:
      %487 = llvm.load %486 : !llvm.ptr -> i32
      %488 = llvm.load %362 : !llvm.ptr -> i32
      %489 = arith.cmpi slt, %487, %488 : i32
      cf.cond_br %489, ^bb79, ^bb80
      ^bb79:
        %491 = llvm.load %486 : !llvm.ptr -> i32
        %492 = arith.extsi %491 : i32 to i64
        %493 = llvm.getelementptr %280[%492] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %490 = llvm.load %493 : !llvm.ptr -> i64
        %494 = arith.constant 1 : i32
        %496 = arith.extsi %494 : i32 to i64
        %495 = arith.subi %490, %496 : i64
        %497 = llvm.mlir.addressof @MOD : !llvm.ptr
        %498 = llvm.load %497 : !llvm.ptr -> i64
        %499 = arith.remsi %495, %498 : i64
        %500 = llvm.mlir.constant(1 : i64) : i64
        %501 = llvm.alloca %500 x i64 : (i64) -> !llvm.ptr
        llvm.store %499, %501 : i64, !llvm.ptr
        %502 = llvm.load %501 : !llvm.ptr -> i64
        %503 = arith.constant 0 : i32
        %505 = arith.extsi %503 : i32 to i64
        %504 = arith.cmpi slt, %502, %505 : i64
        cf.cond_br %504, ^bb81, ^bb82
        ^bb81:
          %506 = llvm.load %501 : !llvm.ptr -> i64
          %507 = llvm.mlir.addressof @MOD : !llvm.ptr
          %508 = llvm.load %507 : !llvm.ptr -> i64
          %509 = arith.addi %506, %508 : i64
          llvm.store %509, %501 : i64, !llvm.ptr
          cf.br ^bb83
        ^bb82:
          cf.br ^bb83
        ^bb83:
        %510 = llvm.load %483 : !llvm.ptr -> i64
        %511 = arith.extsi %510 : i64 to i128
        %512 = llvm.load %501 : !llvm.ptr -> i64
        %514 = arith.trunci %511 : i128 to i64
        %513 = arith.muli %514, %512 : i64
        %515 = llvm.mlir.addressof @MOD : !llvm.ptr
        %516 = llvm.load %515 : !llvm.ptr -> i64
        %517 = arith.remsi %513, %516 : i64
        %519 = llvm.load %486 : !llvm.ptr -> i32
        %520 = arith.extsi %519 : i32 to i64
        %521 = llvm.getelementptr %295[%520] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %518 = llvm.load %521 : !llvm.ptr -> i64
        %522 = arith.muli %517, %518 : i64
        %523 = llvm.mlir.addressof @MOD : !llvm.ptr
        %524 = llvm.load %523 : !llvm.ptr -> i64
        %525 = arith.remsi %522, %524 : i64
        llvm.store %525, %483 : i64, !llvm.ptr
        %526 = llvm.load %486 : !llvm.ptr -> i32
        %527 = arith.constant 1 : i32
        %528 = arith.addi %526, %527 : i32
        llvm.store %528, %486 : i32, !llvm.ptr
        cf.br ^bb78
      ^bb80:
      %529 = llvm.load %366 : !llvm.ptr -> i64
      %530 = llvm.load %483 : !llvm.ptr -> i64
      %531 = arith.addi %529, %530 : i64
      %532 = llvm.mlir.addressof @MOD : !llvm.ptr
      %533 = llvm.load %532 : !llvm.ptr -> i64
      %534 = arith.remsi %531, %533 : i64
      llvm.store %534, %366 : i64, !llvm.ptr
      %535 = llvm.load %369 : !llvm.ptr -> i32
      %536 = arith.constant 1 : i32
      %537 = arith.addi %535, %536 : i32
      llvm.store %537, %369 : i32, !llvm.ptr
      cf.br ^bb63
    ^bb65:
    %538 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %539 = llvm.load %366 : !llvm.ptr -> i64
    %540 = llvm.call @printf(%538, %539) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%175) : (!llvm.ptr) -> ()
    func.call @free(%183) : (!llvm.ptr) -> ()
    func.call @free(%256) : (!llvm.ptr) -> ()
    func.call @free(%280) : (!llvm.ptr) -> ()
    func.call @free(%285) : (!llvm.ptr) -> ()
    func.call @free(%290) : (!llvm.ptr) -> ()
    func.call @free(%295) : (!llvm.ptr) -> ()
    %548 = arith.constant 0 : i32
    func.return %548 : i32
  }
}