Problem 447

F(10^14) mod 10^9+7 where F(N)=sum_{n=2..N} R(n), R(n)=sigma*(n)-n (unitary divisor sum). Uses Möbius inversion: sum_{n<=N} sigma*(n) = sum_e μ(e)*e * sum_{k<=N/e^2} k*floor((N/e^2)/k).

Answer530553372
Output530553372
StatusPASS
Native helperno
Runtime2820 ms
Peak memory118848 KB
Time complexityO(n) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

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

Flow source

# Project Euler 447
# F(10^14) mod 10^9+7 where F(N)=sum_{n=2..N} R(n), R(n)=sigma*(n)-n
# (unitary divisor sum). Uses Möbius inversion:
# sum_{n<=N} sigma*(n) = sum_e μ(e)*e * sum_{k<=N/e^2} k*floor((N/e^2)/k).

import euler.nt { isqrt }

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

function sum_k_floor(M: i64, MOD: i64, INV2: i64) -> i64 {
    let mut s: i64 = 0
    let mut k: i64 = 1
    while k <= M {
        let q: i64 = M / k
        let mut maxk: i64 = M / q
        if maxk > M { maxk = M }
        let hi: i64 = maxk
        let lo: i64 = k
        let mut sumk: i64 = ((hi % MOD) * ((hi + 1) % MOD) % MOD) * INV2 % MOD
        let lom1: i64 = lo - 1
        let sub: i64 = ((lom1 % MOD) * ((lom1 + 1) % MOD) % MOD) * INV2 % MOD
        sumk = (sumk - sub) % MOD
        if sumk < 0 { sumk = sumk + MOD }
        s = (s + (q % MOD) * sumk) % MOD
        k = maxk + 1
    }
    return s
}

function main() -> i32 {
    let MOD: i64 = 1000000007
    let INV2: i64 = (MOD + 1) / 2
    let N: i64 = 100000000000000
    let L: i64 = isqrt(N)

    let mu: ptr<i8> = calloc(L + 1, 1)
    let is_comp: ptr<i8> = calloc(L + 1, 1)
    let primes: ptr<i32> = calloc(L / 5 + 10, 4)
    let pref: ptr<i64> = calloc(L + 1, 8)
    if mu == null || is_comp == null || primes == null || pref == null { return 1 }

    mu[1] = 1
    let mut pc: i64 = 0
    let mut i: i64 = 2
    while i <= L {
        if is_comp[i] == 0 {
            primes[pc] = i as i32
            pc = pc + 1
            mu[i] = -1
        }
        let mut j: i64 = 0
        while j < pc {
            let p: i64 = primes[j] as i64
            let ip: i64 = i * p
            if ip > L { break }
            is_comp[ip] = 1
            if i % p == 0 {
                mu[ip] = 0
                break
            }
            mu[ip] = (0 - (mu[i] as i64)) as i8
            j = j + 1
        }
        i = i + 1
    }

    i = 1
    while i <= L {
        let term: i64 = (mu[i] as i64) * (i % MOD) % MOD
        pref[i] = (pref[i - 1] + term) % MOD
        if pref[i] < 0 { pref[i] = pref[i] + MOD }
        i = i + 1
    }

    # cache for sum_k_floor(M): open-address hash
    let HCAP: i64 = 1 << 20
    let keys: ptr<i64> = calloc(HCAP, 8)
    let vals: ptr<i64> = calloc(HCAP, 8)
    let used: ptr<i8> = calloc(HCAP, 1)
    if keys == null || vals == null || used == null { return 1 }

    let mut total: i64 = 0
    let mut e: i64 = 1
    while e <= L {
        let M: i64 = N / (e * e)
        if M == 0 { break }

        # largest e2 with N/(e2*e2) == M
        let mut e2: i64 = isqrt(N / M)
        if e2 > L { e2 = L }
        if e2 < e { e2 = e }
        while e2 > e && N / (e2 * e2) < M {
            e2 = e2 - 1
        }
        while e2 + 1 <= L && N / ((e2 + 1) * (e2 + 1)) == M {
            e2 = e2 + 1
        }

        let mut sum_emu: i64 = (pref[e2] - pref[e - 1]) % MOD
        if sum_emu < 0 { sum_emu = sum_emu + MOD }

        # cached sum_k_floor(M)
        let mut h: i64 = M % HCAP
        let mut piece: i64 = -1
        while used[h] != 0 {
            if keys[h] == M {
                piece = vals[h]
                break
            }
            h = h + 1
            if h >= HCAP { h = 0 }
        }
        if piece < 0 {
            piece = sum_k_floor(M, MOD, INV2)
            used[h] = 1
            keys[h] = M
            vals[h] = piece
        }

        total = (total + sum_emu * piece) % MOD
        e = e2 + 1
    }

    let tri: i64 = ((N % MOD) * ((N + 1) % MOD) % MOD) * INV2 % MOD
    let ans: i64 = (total - tri) % MOD
    if ans < 0 { ans = ans + MOD }
    printf("%lld\n", ans)

    free(used)
    free(vals)
    free(keys)
    free(pref)
    free(primes)
    free(is_comp)
    free(mu)
    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);
int64_t sum_k_floor_i64_i64_i64(int64_t M, int64_t MOD, int64_t INV2);
int32_t main(void);

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;
}



int64_t sum_k_floor_i64_i64_i64(int64_t M, int64_t MOD, int64_t INV2) {
    int64_t s = 0;
    int64_t k = 1;
    while (k <= M) {
        int64_t q = FLOW_CHECKED_DIV((M), (k));
        int64_t maxk = FLOW_CHECKED_DIV((M), (q));
        if (maxk > M) {
            maxk = M;
        }
        int64_t hi = maxk;
        int64_t lo = k;
        int64_t sumk = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((hi), (MOD)) * FLOW_CHECKED_MOD(((hi + 1)), (MOD)))), (MOD)) * INV2)), (MOD));
        int64_t lom1 = (lo - 1);
        int64_t sub = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((lom1), (MOD)) * FLOW_CHECKED_MOD(((lom1 + 1)), (MOD)))), (MOD)) * INV2)), (MOD));
        sumk = FLOW_CHECKED_MOD(((sumk - sub)), (MOD));
        if (sumk < 0) {
            sumk = (sumk + MOD);
        }
        s = FLOW_CHECKED_MOD(((s + (FLOW_CHECKED_MOD((q), (MOD)) * sumk))), (MOD));
        k = (maxk + 1);
    }
    return s;
}

int32_t main(void) {
    int64_t MOD = 1000000007;
    int64_t INV2 = FLOW_CHECKED_DIV(((MOD + 1)), (2));
    int64_t N = 100000000000000;
    int64_t L = isqrt_i64(N);
    int8_t* mu = (int8_t*)(calloc((L + 1), 1));
    int8_t* is_comp = (int8_t*)(calloc((L + 1), 1));
    int32_t* primes = (int32_t*)(calloc((FLOW_CHECKED_DIV((L), (5)) + 10), 4));
    int64_t* pref = (int64_t*)(calloc((L + 1), 8));
    if ((((mu == NULL || is_comp == NULL) || primes == NULL) || pref == NULL)) {
        return 1;
    }
    mu[1] = 1;
    int64_t pc = 0;
    int64_t i = 2;
    while (i <= L) {
        if (is_comp[i] == 0) {
            primes[pc] = ((int32_t)(i));
            pc = (pc + 1);
            mu[i] = (-1);
        }
        int64_t j = 0;
        while (j < pc) {
            int64_t p = ((int64_t)(primes[j]));
            int64_t ip = (i * p);
            if (ip > L) {
                break;
            }
            is_comp[ip] = 1;
            if (FLOW_CHECKED_MOD((i), (p)) == 0) {
                mu[ip] = 0;
                break;
            }
            mu[ip] = ((int8_t)((0 - ((int64_t)(mu[i])))));
            j = (j + 1);
        }
        i = (i + 1);
    }
    i = 1;
    while (i <= L) {
        int64_t term = FLOW_CHECKED_MOD(((((int64_t)(mu[i])) * FLOW_CHECKED_MOD((i), (MOD)))), (MOD));
        pref[i] = FLOW_CHECKED_MOD(((pref[(i - 1)] + term)), (MOD));
        if (pref[i] < 0) {
            pref[i] = (pref[i] + MOD);
        }
        i = (i + 1);
    }
    int64_t HCAP = FLOW_CHECKED_SHL((1), (20));
    int64_t* keys = (int64_t*)(calloc(HCAP, 8));
    int64_t* vals = (int64_t*)(calloc(HCAP, 8));
    int8_t* used = (int8_t*)(calloc(HCAP, 1));
    if (((keys == NULL || vals == NULL) || used == NULL)) {
        return 1;
    }
    int64_t total = 0;
    int64_t e = 1;
    while (e <= L) {
        int64_t M = FLOW_CHECKED_DIV((N), ((e * e)));
        if (M == 0) {
            break;
        }
        int64_t e2 = isqrt_i64(FLOW_CHECKED_DIV((N), (M)));
        if (e2 > L) {
            e2 = L;
        }
        if (e2 < e) {
            e2 = e;
        }
        while ((e2 > e && FLOW_CHECKED_DIV((N), ((e2 * e2))) < M)) {
            e2 = (e2 - 1);
        }
        while (((e2 + 1) <= L && FLOW_CHECKED_DIV((N), (((e2 + 1) * (e2 + 1)))) == M)) {
            e2 = (e2 + 1);
        }
        int64_t sum_emu = FLOW_CHECKED_MOD(((pref[e2] - pref[(e - 1)])), (MOD));
        if (sum_emu < 0) {
            sum_emu = (sum_emu + MOD);
        }
        int64_t h = FLOW_CHECKED_MOD((M), (HCAP));
        int64_t piece = (-1);
        while (used[h] != 0) {
            if (keys[h] == M) {
                piece = vals[h];
                break;
            }
            h = (h + 1);
            if (h >= HCAP) {
                h = 0;
            }
        }
        if (piece < 0) {
            piece = sum_k_floor_i64_i64_i64(M, MOD, INV2);
            used[h] = 1;
            keys[h] = M;
            vals[h] = piece;
        }
        total = FLOW_CHECKED_MOD(((total + (sum_emu * piece))), (MOD));
        e = (e2 + 1);
    }
    int64_t tri = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((N), (MOD)) * FLOW_CHECKED_MOD(((N + 1)), (MOD)))), (MOD)) * INV2)), (MOD));
    int64_t ans = FLOW_CHECKED_MOD(((total - tri)), (MOD));
    if (ans < 0) {
        ans = (ans + MOD);
    }
    printf("%lld\n", ans);
    free(used);
    free(vals);
    free(keys);
    free(pref);
    free(primes);
    free(is_comp);
    free(mu);
    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) -> ()
  func.func @sum_k_floor(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %175 = arith.constant 0 : i32
    %176 = arith.extsi %175 : i32 to i64
    %177 = llvm.mlir.constant(1 : i64) : i64
    %178 = llvm.alloca %177 x i64 : (i64) -> !llvm.ptr
    llvm.store %176, %178 : i64, !llvm.ptr
    %179 = arith.constant 1 : i32
    %180 = arith.extsi %179 : i32 to i64
    %181 = llvm.mlir.constant(1 : i64) : i64
    %182 = llvm.alloca %181 x i64 : (i64) -> !llvm.ptr
    llvm.store %180, %182 : i64, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %183 = llvm.load %182 : !llvm.ptr -> i64
    %184 = arith.cmpi sle, %183, %arg0 : i64
    cf.cond_br %184, ^bb43, ^bb44
    ^bb43:
      %185 = llvm.load %182 : !llvm.ptr -> i64
      %186 = arith.divsi %arg0, %185 : i64
      %187 = arith.divsi %arg0, %186 : i64
      %188 = llvm.mlir.constant(1 : i64) : i64
      %189 = llvm.alloca %188 x i64 : (i64) -> !llvm.ptr
      llvm.store %187, %189 : i64, !llvm.ptr
      %190 = llvm.load %189 : !llvm.ptr -> i64
      %191 = arith.cmpi sgt, %190, %arg0 : i64
      cf.cond_br %191, ^bb45, ^bb46
      ^bb45:
        llvm.store %arg0, %189 : i64, !llvm.ptr
        cf.br ^bb47
      ^bb46:
        cf.br ^bb47
      ^bb47:
      %192 = llvm.load %189 : !llvm.ptr -> i64
      %193 = llvm.load %182 : !llvm.ptr -> i64
      %194 = arith.remsi %192, %arg1 : i64
      %195 = arith.constant 1 : i32
      %197 = arith.extsi %195 : i32 to i64
      %196 = arith.addi %192, %197 : i64
      %198 = arith.remsi %196, %arg1 : i64
      %199 = arith.muli %194, %198 : i64
      %200 = arith.remsi %199, %arg1 : i64
      %201 = arith.muli %200, %arg2 : i64
      %202 = arith.remsi %201, %arg1 : i64
      %203 = llvm.mlir.constant(1 : i64) : i64
      %204 = llvm.alloca %203 x i64 : (i64) -> !llvm.ptr
      llvm.store %202, %204 : i64, !llvm.ptr
      %205 = arith.constant 1 : i32
      %207 = arith.extsi %205 : i32 to i64
      %206 = arith.subi %193, %207 : i64
      %208 = arith.remsi %206, %arg1 : i64
      %209 = arith.constant 1 : i32
      %211 = arith.extsi %209 : i32 to i64
      %210 = arith.addi %206, %211 : i64
      %212 = arith.remsi %210, %arg1 : i64
      %213 = arith.muli %208, %212 : i64
      %214 = arith.remsi %213, %arg1 : i64
      %215 = arith.muli %214, %arg2 : i64
      %216 = arith.remsi %215, %arg1 : i64
      %217 = llvm.load %204 : !llvm.ptr -> i64
      %218 = arith.subi %217, %216 : i64
      %219 = arith.remsi %218, %arg1 : i64
      llvm.store %219, %204 : i64, !llvm.ptr
      %220 = llvm.load %204 : !llvm.ptr -> i64
      %221 = arith.constant 0 : i32
      %223 = arith.extsi %221 : i32 to i64
      %222 = arith.cmpi slt, %220, %223 : i64
      cf.cond_br %222, ^bb48, ^bb49
      ^bb48:
        %224 = llvm.load %204 : !llvm.ptr -> i64
        %225 = arith.addi %224, %arg1 : i64
        llvm.store %225, %204 : i64, !llvm.ptr
        cf.br ^bb50
      ^bb49:
        cf.br ^bb50
      ^bb50:
      %226 = llvm.load %178 : !llvm.ptr -> i64
      %227 = arith.remsi %186, %arg1 : i64
      %228 = llvm.load %204 : !llvm.ptr -> i64
      %229 = arith.muli %227, %228 : i64
      %230 = arith.addi %226, %229 : i64
      %231 = arith.remsi %230, %arg1 : i64
      llvm.store %231, %178 : i64, !llvm.ptr
      %232 = llvm.load %189 : !llvm.ptr -> i64
      %233 = arith.constant 1 : i32
      %235 = arith.extsi %233 : i32 to i64
      %234 = arith.addi %232, %235 : i64
      llvm.store %234, %182 : i64, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    %236 = llvm.load %178 : !llvm.ptr -> i64
    func.return %236 : i64
  }
  func.func @main() -> i32 {
    %237 = arith.constant 1000000007 : i32
    %238 = arith.extsi %237 : i32 to i64
    %239 = arith.constant 1 : i32
    %241 = arith.extsi %239 : i32 to i64
    %240 = arith.addi %238, %241 : i64
    %242 = arith.constant 2 : i32
    %244 = arith.extsi %242 : i32 to i64
    %243 = arith.divsi %240, %244 : i64
    %245 = arith.constant 99995705032704 : i32
    %246 = arith.extsi %245 : i32 to i64
    %247 = func.call @isqrt(%246) : (i64) -> i64
    %249 = arith.constant 1 : i32
    %251 = arith.extsi %249 : i32 to i64
    %250 = arith.addi %247, %251 : i64
    %252 = arith.constant 1 : i32
    %253 = arith.extsi %252 : i32 to i64
    %248 = func.call @calloc(%250, %253) : (i64, i64) -> !llvm.ptr
    %255 = arith.constant 1 : i32
    %257 = arith.extsi %255 : i32 to i64
    %256 = arith.addi %247, %257 : i64
    %258 = arith.constant 1 : i32
    %259 = arith.extsi %258 : i32 to i64
    %254 = func.call @calloc(%256, %259) : (i64, i64) -> !llvm.ptr
    %261 = arith.constant 5 : i32
    %263 = arith.extsi %261 : i32 to i64
    %262 = arith.divsi %247, %263 : i64
    %264 = arith.constant 10 : i32
    %266 = arith.extsi %264 : i32 to i64
    %265 = arith.addi %262, %266 : i64
    %267 = arith.constant 4 : i32
    %268 = arith.extsi %267 : i32 to i64
    %260 = func.call @calloc(%265, %268) : (i64, i64) -> !llvm.ptr
    %270 = arith.constant 1 : i32
    %272 = arith.extsi %270 : i32 to i64
    %271 = arith.addi %247, %272 : i64
    %273 = arith.constant 8 : i32
    %274 = arith.extsi %273 : i32 to i64
    %269 = func.call @calloc(%271, %274) : (i64, i64) -> !llvm.ptr
    %275 = llvm.mlir.zero : !llvm.ptr
    %276 = llvm.icmp "eq" %248, %275 : !llvm.ptr
    %277 = scf.if %276 -> (i1) {
      %278 = arith.constant true
      scf.yield %278 : i1
    } else {
      %279 = llvm.mlir.zero : !llvm.ptr
      %280 = llvm.icmp "eq" %254, %279 : !llvm.ptr
      scf.yield %280 : i1
    }
    %281 = scf.if %277 -> (i1) {
      %282 = arith.constant true
      scf.yield %282 : i1
    } else {
      %283 = llvm.mlir.zero : !llvm.ptr
      %284 = llvm.icmp "eq" %260, %283 : !llvm.ptr
      scf.yield %284 : i1
    }
    %285 = scf.if %281 -> (i1) {
      %286 = arith.constant true
      scf.yield %286 : i1
    } else {
      %287 = llvm.mlir.zero : !llvm.ptr
      %288 = llvm.icmp "eq" %269, %287 : !llvm.ptr
      scf.yield %288 : i1
    }
    cf.cond_br %285, ^bb51, ^bb52
    ^bb51:
      %289 = arith.constant 1 : i32
      func.return %289 : i32
    ^bb52:
      cf.br ^bb53
    ^bb53:
    %290 = arith.constant 1 : i32
    %291 = arith.constant 1 : i32
    %292 = arith.trunci %290 : i32 to i8
    %293 = arith.extsi %291 : i32 to i64
    %294 = llvm.getelementptr %248[%293] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %292, %294 : i8, !llvm.ptr
    %295 = arith.constant 0 : i32
    %296 = arith.extsi %295 : i32 to i64
    %297 = llvm.mlir.constant(1 : i64) : i64
    %298 = llvm.alloca %297 x i64 : (i64) -> !llvm.ptr
    llvm.store %296, %298 : i64, !llvm.ptr
    %299 = arith.constant 2 : i32
    %300 = arith.extsi %299 : i32 to i64
    %301 = llvm.mlir.constant(1 : i64) : i64
    %302 = llvm.alloca %301 x i64 : (i64) -> !llvm.ptr
    llvm.store %300, %302 : i64, !llvm.ptr
    cf.br ^bb54
    ^bb54:
    %303 = llvm.load %302 : !llvm.ptr -> i64
    %304 = arith.cmpi sle, %303, %247 : i64
    cf.cond_br %304, ^bb55, ^bb56
    ^bb55:
      %306 = llvm.load %302 : !llvm.ptr -> i64
      %307 = llvm.getelementptr %254[%306] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %305 = llvm.load %307 : !llvm.ptr -> i8
      %308 = arith.constant 0 : i32
      %310 = arith.extsi %305 : i8 to i32
      %309 = arith.cmpi eq, %310, %308 : i32
      cf.cond_br %309, ^bb57, ^bb58
      ^bb57:
        %311 = llvm.load %302 : !llvm.ptr -> i64
        %312 = arith.trunci %311 : i64 to i32
        %313 = llvm.load %298 : !llvm.ptr -> i64
        %314 = llvm.getelementptr %260[%313] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %312, %314 : i32, !llvm.ptr
        %315 = llvm.load %298 : !llvm.ptr -> i64
        %316 = arith.constant 1 : i32
        %318 = arith.extsi %316 : i32 to i64
        %317 = arith.addi %315, %318 : i64
        llvm.store %317, %298 : i64, !llvm.ptr
        %319 = arith.constant 1 : i32
        %321 = arith.constant 0 : i32
        %320 = arith.subi %321, %319 : i32
        %322 = llvm.load %302 : !llvm.ptr -> i64
        %323 = arith.trunci %320 : i32 to i8
        %324 = llvm.getelementptr %248[%322] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        llvm.store %323, %324 : i8, !llvm.ptr
        cf.br ^bb59
      ^bb58:
        cf.br ^bb59
      ^bb59:
      %325 = arith.constant 0 : i32
      %326 = arith.extsi %325 : i32 to i64
      %327 = llvm.mlir.constant(1 : i64) : i64
      %328 = llvm.alloca %327 x i64 : (i64) -> !llvm.ptr
      llvm.store %326, %328 : i64, !llvm.ptr
      cf.br ^bb60
      ^bb60:
      %329 = llvm.load %328 : !llvm.ptr -> i64
      %330 = llvm.load %298 : !llvm.ptr -> i64
      %331 = arith.cmpi slt, %329, %330 : i64
      cf.cond_br %331, ^bb61, ^bb62
      ^bb61:
        %333 = llvm.load %328 : !llvm.ptr -> i64
        %334 = llvm.getelementptr %260[%333] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %332 = llvm.load %334 : !llvm.ptr -> i32
        %335 = arith.extsi %332 : i32 to i64
        %336 = llvm.load %302 : !llvm.ptr -> i64
        %337 = arith.muli %336, %335 : i64
        %338 = arith.cmpi sgt, %337, %247 : i64
        cf.cond_br %338, ^bb63, ^bb64
        ^bb63:
          cf.br ^bb62
        ^bb64:
          cf.br ^bb65
        ^bb65:
        %339 = arith.constant 1 : i32
        %340 = arith.trunci %339 : i32 to i8
        %341 = llvm.getelementptr %254[%337] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        llvm.store %340, %341 : i8, !llvm.ptr
        %342 = llvm.load %302 : !llvm.ptr -> i64
        %343 = arith.remsi %342, %335 : i64
        %344 = arith.constant 0 : i32
        %346 = arith.extsi %344 : i32 to i64
        %345 = arith.cmpi eq, %343, %346 : i64
        cf.cond_br %345, ^bb66, ^bb67
        ^bb66:
          %347 = arith.constant 0 : i32
          %348 = arith.trunci %347 : i32 to i8
          %349 = llvm.getelementptr %248[%337] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %348, %349 : i8, !llvm.ptr
          cf.br ^bb62
        ^bb67:
          cf.br ^bb68
        ^bb68:
        %350 = arith.constant 0 : i32
        %352 = llvm.load %302 : !llvm.ptr -> i64
        %353 = llvm.getelementptr %248[%352] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        %351 = llvm.load %353 : !llvm.ptr -> i8
        %354 = arith.extsi %351 : i8 to i64
        %356 = arith.extsi %350 : i32 to i64
        %355 = arith.subi %356, %354 : i64
        %357 = arith.trunci %355 : i64 to i8
        %358 = llvm.getelementptr %248[%337] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        llvm.store %357, %358 : i8, !llvm.ptr
        %359 = llvm.load %328 : !llvm.ptr -> i64
        %360 = arith.constant 1 : i32
        %362 = arith.extsi %360 : i32 to i64
        %361 = arith.addi %359, %362 : i64
        llvm.store %361, %328 : i64, !llvm.ptr
        cf.br ^bb60
      ^bb62:
      %363 = llvm.load %302 : !llvm.ptr -> i64
      %364 = arith.constant 1 : i32
      %366 = arith.extsi %364 : i32 to i64
      %365 = arith.addi %363, %366 : i64
      llvm.store %365, %302 : i64, !llvm.ptr
      cf.br ^bb54
    ^bb56:
    %367 = arith.constant 1 : i32
    %368 = arith.extsi %367 : i32 to i64
    llvm.store %368, %302 : i64, !llvm.ptr
    cf.br ^bb69
    ^bb69:
    %369 = llvm.load %302 : !llvm.ptr -> i64
    %370 = arith.cmpi sle, %369, %247 : i64
    cf.cond_br %370, ^bb70, ^bb71
    ^bb70:
      %372 = llvm.load %302 : !llvm.ptr -> i64
      %373 = llvm.getelementptr %248[%372] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %371 = llvm.load %373 : !llvm.ptr -> i8
      %374 = arith.extsi %371 : i8 to i64
      %375 = llvm.load %302 : !llvm.ptr -> i64
      %376 = arith.remsi %375, %238 : i64
      %377 = arith.muli %374, %376 : i64
      %378 = arith.remsi %377, %238 : i64
      %380 = llvm.load %302 : !llvm.ptr -> i64
      %381 = arith.constant 1 : i32
      %383 = arith.extsi %381 : i32 to i64
      %382 = arith.subi %380, %383 : i64
      %384 = llvm.getelementptr %269[%382] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %379 = llvm.load %384 : !llvm.ptr -> i64
      %385 = arith.addi %379, %378 : i64
      %386 = arith.remsi %385, %238 : i64
      %387 = llvm.load %302 : !llvm.ptr -> i64
      %388 = llvm.getelementptr %269[%387] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %386, %388 : i64, !llvm.ptr
      %390 = llvm.load %302 : !llvm.ptr -> i64
      %391 = llvm.getelementptr %269[%390] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %389 = llvm.load %391 : !llvm.ptr -> i64
      %392 = arith.constant 0 : i32
      %394 = arith.extsi %392 : i32 to i64
      %393 = arith.cmpi slt, %389, %394 : i64
      cf.cond_br %393, ^bb72, ^bb73
      ^bb72:
        %396 = llvm.load %302 : !llvm.ptr -> i64
        %397 = llvm.getelementptr %269[%396] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %395 = llvm.load %397 : !llvm.ptr -> i64
        %398 = arith.addi %395, %238 : i64
        %399 = llvm.load %302 : !llvm.ptr -> i64
        %400 = llvm.getelementptr %269[%399] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %398, %400 : i64, !llvm.ptr
        cf.br ^bb74
      ^bb73:
        cf.br ^bb74
      ^bb74:
      %401 = llvm.load %302 : !llvm.ptr -> i64
      %402 = arith.constant 1 : i32
      %404 = arith.extsi %402 : i32 to i64
      %403 = arith.addi %401, %404 : i64
      llvm.store %403, %302 : i64, !llvm.ptr
      cf.br ^bb69
    ^bb71:
    %405 = arith.constant 1 : i32
    %406 = arith.constant 20 : i32
    %407 = arith.shli %405, %406 : i32
    %408 = arith.extsi %407 : i32 to i64
    %410 = arith.constant 8 : i32
    %411 = arith.extsi %410 : i32 to i64
    %409 = func.call @calloc(%408, %411) : (i64, i64) -> !llvm.ptr
    %413 = arith.constant 8 : i32
    %414 = arith.extsi %413 : i32 to i64
    %412 = func.call @calloc(%408, %414) : (i64, i64) -> !llvm.ptr
    %416 = arith.constant 1 : i32
    %417 = arith.extsi %416 : i32 to i64
    %415 = func.call @calloc(%408, %417) : (i64, i64) -> !llvm.ptr
    %418 = llvm.mlir.zero : !llvm.ptr
    %419 = llvm.icmp "eq" %409, %418 : !llvm.ptr
    %420 = scf.if %419 -> (i1) {
      %421 = arith.constant true
      scf.yield %421 : i1
    } else {
      %422 = llvm.mlir.zero : !llvm.ptr
      %423 = llvm.icmp "eq" %412, %422 : !llvm.ptr
      scf.yield %423 : i1
    }
    %424 = scf.if %420 -> (i1) {
      %425 = arith.constant true
      scf.yield %425 : i1
    } else {
      %426 = llvm.mlir.zero : !llvm.ptr
      %427 = llvm.icmp "eq" %415, %426 : !llvm.ptr
      scf.yield %427 : i1
    }
    cf.cond_br %424, ^bb75, ^bb76
    ^bb75:
      %428 = arith.constant 1 : i32
      func.return %428 : i32
    ^bb76:
      cf.br ^bb77
    ^bb77:
    %429 = arith.constant 0 : i32
    %430 = arith.extsi %429 : i32 to i64
    %431 = llvm.mlir.constant(1 : i64) : i64
    %432 = llvm.alloca %431 x i64 : (i64) -> !llvm.ptr
    llvm.store %430, %432 : i64, !llvm.ptr
    %433 = arith.constant 1 : i32
    %434 = arith.extsi %433 : i32 to i64
    %435 = llvm.mlir.constant(1 : i64) : i64
    %436 = llvm.alloca %435 x i64 : (i64) -> !llvm.ptr
    llvm.store %434, %436 : i64, !llvm.ptr
    cf.br ^bb78
    ^bb78:
    %437 = llvm.load %436 : !llvm.ptr -> i64
    %438 = arith.cmpi sle, %437, %247 : i64
    cf.cond_br %438, ^bb79, ^bb80
    ^bb79:
      %439 = llvm.load %436 : !llvm.ptr -> i64
      %440 = llvm.load %436 : !llvm.ptr -> i64
      %441 = arith.muli %439, %440 : i64
      %442 = arith.divsi %246, %441 : i64
      %443 = arith.constant 0 : i32
      %445 = arith.extsi %443 : i32 to i64
      %444 = arith.cmpi eq, %442, %445 : i64
      cf.cond_br %444, ^bb81, ^bb82
      ^bb81:
        cf.br ^bb80
      ^bb82:
        cf.br ^bb83
      ^bb83:
      %447 = arith.divsi %246, %442 : i64
      %446 = func.call @isqrt(%447) : (i64) -> i64
      %448 = llvm.mlir.constant(1 : i64) : i64
      %449 = llvm.alloca %448 x i64 : (i64) -> !llvm.ptr
      llvm.store %446, %449 : i64, !llvm.ptr
      %450 = llvm.load %449 : !llvm.ptr -> i64
      %451 = arith.cmpi sgt, %450, %247 : i64
      cf.cond_br %451, ^bb84, ^bb85
      ^bb84:
        llvm.store %247, %449 : i64, !llvm.ptr
        cf.br ^bb86
      ^bb85:
        cf.br ^bb86
      ^bb86:
      %452 = llvm.load %449 : !llvm.ptr -> i64
      %453 = llvm.load %436 : !llvm.ptr -> i64
      %454 = arith.cmpi slt, %452, %453 : i64
      cf.cond_br %454, ^bb87, ^bb88
      ^bb87:
        %455 = llvm.load %436 : !llvm.ptr -> i64
        llvm.store %455, %449 : i64, !llvm.ptr
        cf.br ^bb89
      ^bb88:
        cf.br ^bb89
      ^bb89:
      cf.br ^bb90
      ^bb90:
      %456 = llvm.load %449 : !llvm.ptr -> i64
      %457 = llvm.load %436 : !llvm.ptr -> i64
      %458 = arith.cmpi sgt, %456, %457 : i64
      %459 = scf.if %458 -> (i1) {
        %460 = llvm.load %449 : !llvm.ptr -> i64
        %461 = llvm.load %449 : !llvm.ptr -> i64
        %462 = arith.muli %460, %461 : i64
        %463 = arith.divsi %246, %462 : i64
        %464 = arith.cmpi slt, %463, %442 : i64
        scf.yield %464 : i1
      } else {
        %465 = arith.constant false
        scf.yield %465 : i1
      }
      cf.cond_br %459, ^bb91, ^bb92
      ^bb91:
        %466 = llvm.load %449 : !llvm.ptr -> i64
        %467 = arith.constant 1 : i32
        %469 = arith.extsi %467 : i32 to i64
        %468 = arith.subi %466, %469 : i64
        llvm.store %468, %449 : i64, !llvm.ptr
        cf.br ^bb90
      ^bb92:
      cf.br ^bb93
      ^bb93:
      %470 = llvm.load %449 : !llvm.ptr -> i64
      %471 = arith.constant 1 : i32
      %473 = arith.extsi %471 : i32 to i64
      %472 = arith.addi %470, %473 : i64
      %474 = arith.cmpi sle, %472, %247 : i64
      %475 = scf.if %474 -> (i1) {
        %476 = llvm.load %449 : !llvm.ptr -> i64
        %477 = arith.constant 1 : i32
        %479 = arith.extsi %477 : i32 to i64
        %478 = arith.addi %476, %479 : i64
        %480 = llvm.load %449 : !llvm.ptr -> i64
        %481 = arith.constant 1 : i32
        %483 = arith.extsi %481 : i32 to i64
        %482 = arith.addi %480, %483 : i64
        %484 = arith.muli %478, %482 : i64
        %485 = arith.divsi %246, %484 : i64
        %486 = arith.cmpi eq, %485, %442 : i64
        scf.yield %486 : i1
      } else {
        %487 = arith.constant false
        scf.yield %487 : i1
      }
      cf.cond_br %475, ^bb94, ^bb95
      ^bb94:
        %488 = llvm.load %449 : !llvm.ptr -> i64
        %489 = arith.constant 1 : i32
        %491 = arith.extsi %489 : i32 to i64
        %490 = arith.addi %488, %491 : i64
        llvm.store %490, %449 : i64, !llvm.ptr
        cf.br ^bb93
      ^bb95:
      %493 = llvm.load %449 : !llvm.ptr -> i64
      %494 = llvm.getelementptr %269[%493] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %492 = llvm.load %494 : !llvm.ptr -> i64
      %496 = llvm.load %436 : !llvm.ptr -> i64
      %497 = arith.constant 1 : i32
      %499 = arith.extsi %497 : i32 to i64
      %498 = arith.subi %496, %499 : i64
      %500 = llvm.getelementptr %269[%498] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %495 = llvm.load %500 : !llvm.ptr -> i64
      %501 = arith.subi %492, %495 : i64
      %502 = arith.remsi %501, %238 : i64
      %503 = llvm.mlir.constant(1 : i64) : i64
      %504 = llvm.alloca %503 x i64 : (i64) -> !llvm.ptr
      llvm.store %502, %504 : i64, !llvm.ptr
      %505 = llvm.load %504 : !llvm.ptr -> i64
      %506 = arith.constant 0 : i32
      %508 = arith.extsi %506 : i32 to i64
      %507 = arith.cmpi slt, %505, %508 : i64
      cf.cond_br %507, ^bb96, ^bb97
      ^bb96:
        %509 = llvm.load %504 : !llvm.ptr -> i64
        %510 = arith.addi %509, %238 : i64
        llvm.store %510, %504 : i64, !llvm.ptr
        cf.br ^bb98
      ^bb97:
        cf.br ^bb98
      ^bb98:
      %511 = arith.remsi %442, %408 : i64
      %512 = llvm.mlir.constant(1 : i64) : i64
      %513 = llvm.alloca %512 x i64 : (i64) -> !llvm.ptr
      llvm.store %511, %513 : i64, !llvm.ptr
      %514 = arith.constant 1 : i32
      %516 = arith.constant 0 : i32
      %515 = arith.subi %516, %514 : i32
      %517 = arith.extsi %515 : i32 to i64
      %518 = llvm.mlir.constant(1 : i64) : i64
      %519 = llvm.alloca %518 x i64 : (i64) -> !llvm.ptr
      llvm.store %517, %519 : i64, !llvm.ptr
      cf.br ^bb99
      ^bb99:
      %521 = llvm.load %513 : !llvm.ptr -> i64
      %522 = llvm.getelementptr %415[%521] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %520 = llvm.load %522 : !llvm.ptr -> i8
      %523 = arith.constant 0 : i32
      %525 = arith.extsi %520 : i8 to i32
      %524 = arith.cmpi ne, %525, %523 : i32
      cf.cond_br %524, ^bb100, ^bb101
      ^bb100:
        %527 = llvm.load %513 : !llvm.ptr -> i64
        %528 = llvm.getelementptr %409[%527] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %526 = llvm.load %528 : !llvm.ptr -> i64
        %529 = arith.cmpi eq, %526, %442 : i64
        cf.cond_br %529, ^bb102, ^bb103
        ^bb102:
          %531 = llvm.load %513 : !llvm.ptr -> i64
          %532 = llvm.getelementptr %412[%531] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %530 = llvm.load %532 : !llvm.ptr -> i64
          llvm.store %530, %519 : i64, !llvm.ptr
          cf.br ^bb101
        ^bb103:
          cf.br ^bb104
        ^bb104:
        %533 = llvm.load %513 : !llvm.ptr -> i64
        %534 = arith.constant 1 : i32
        %536 = arith.extsi %534 : i32 to i64
        %535 = arith.addi %533, %536 : i64
        llvm.store %535, %513 : i64, !llvm.ptr
        %537 = llvm.load %513 : !llvm.ptr -> i64
        %538 = arith.cmpi sge, %537, %408 : i64
        cf.cond_br %538, ^bb105, ^bb106
        ^bb105:
          %539 = arith.constant 0 : i32
          %540 = arith.extsi %539 : i32 to i64
          llvm.store %540, %513 : i64, !llvm.ptr
          cf.br ^bb107
        ^bb106:
          cf.br ^bb107
        ^bb107:
        cf.br ^bb99
      ^bb101:
      %541 = llvm.load %519 : !llvm.ptr -> i64
      %542 = arith.constant 0 : i32
      %544 = arith.extsi %542 : i32 to i64
      %543 = arith.cmpi slt, %541, %544 : i64
      cf.cond_br %543, ^bb108, ^bb109
      ^bb108:
        %545 = func.call @sum_k_floor(%442, %238, %243) : (i64, i64, i64) -> i64
        llvm.store %545, %519 : i64, !llvm.ptr
        %546 = arith.constant 1 : i32
        %547 = llvm.load %513 : !llvm.ptr -> i64
        %548 = arith.trunci %546 : i32 to i8
        %549 = llvm.getelementptr %415[%547] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        llvm.store %548, %549 : i8, !llvm.ptr
        %550 = llvm.load %513 : !llvm.ptr -> i64
        %551 = llvm.getelementptr %409[%550] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %442, %551 : i64, !llvm.ptr
        %552 = llvm.load %519 : !llvm.ptr -> i64
        %553 = llvm.load %513 : !llvm.ptr -> i64
        %554 = llvm.getelementptr %412[%553] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %552, %554 : i64, !llvm.ptr
        cf.br ^bb110
      ^bb109:
        cf.br ^bb110
      ^bb110:
      %555 = llvm.load %432 : !llvm.ptr -> i64
      %556 = llvm.load %504 : !llvm.ptr -> i64
      %557 = llvm.load %519 : !llvm.ptr -> i64
      %558 = arith.muli %556, %557 : i64
      %559 = arith.addi %555, %558 : i64
      %560 = arith.remsi %559, %238 : i64
      llvm.store %560, %432 : i64, !llvm.ptr
      %561 = llvm.load %449 : !llvm.ptr -> i64
      %562 = arith.constant 1 : i32
      %564 = arith.extsi %562 : i32 to i64
      %563 = arith.addi %561, %564 : i64
      llvm.store %563, %436 : i64, !llvm.ptr
      cf.br ^bb78
    ^bb80:
    %565 = arith.remsi %246, %238 : i64
    %566 = arith.constant 1 : i32
    %568 = arith.extsi %566 : i32 to i64
    %567 = arith.addi %246, %568 : i64
    %569 = arith.remsi %567, %238 : i64
    %570 = arith.muli %565, %569 : i64
    %571 = arith.remsi %570, %238 : i64
    %572 = arith.muli %571, %243 : i64
    %573 = arith.remsi %572, %238 : i64
    %574 = llvm.load %432 : !llvm.ptr -> i64
    %575 = arith.subi %574, %573 : i64
    %576 = arith.remsi %575, %238 : i64
    %577 = arith.constant 0 : i32
    %579 = arith.extsi %577 : i32 to i64
    %578 = arith.cmpi slt, %576, %579 : i64
    %580 = scf.if %578 -> (i64) {
      %581 = arith.addi %576, %238 : i64
      scf.yield %581 : i64
    } else {
      scf.yield %576 : i64
    }
    %582 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %583 = llvm.call @printf(%582, %580) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%415) : (!llvm.ptr) -> ()
    func.call @free(%412) : (!llvm.ptr) -> ()
    func.call @free(%409) : (!llvm.ptr) -> ()
    func.call @free(%269) : (!llvm.ptr) -> ()
    func.call @free(%260) : (!llvm.ptr) -> ()
    func.call @free(%254) : (!llvm.ptr) -> ()
    func.call @free(%248) : (!llvm.ptr) -> ()
    %591 = arith.constant 0 : i32
    func.return %591 : i32
  }
}