Problem 832

Mex Sequences — M(10^18) mod 1e9+7 via recursive blocks (mod mul for sums).

Answer552839586
Output552839586
StatusPASS
Native helperno
Runtime0 ms
Peak memory1072 KB
Time complexityO(1) (estimated)
Space complexityO(1) (estimated)

Performance comparison

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

Flow source

# Project Euler 832
# Mex Sequences — M(10^18) mod 1e9+7 via recursive blocks (mod mul for sums).

const MOD: i64 = 1000000007

function modmul(a: i64, b: i64) -> i64 {
    let x: i64 = a % MOD
    let y: i64 = b % MOD
    let mut r: i64 = ((x as i128) * (y as i128) % (MOD as i128)) as i64
    if r < 0 { r = r + MOD }
    return r
}

function block_sum(start: i64, power: i64) -> i64 {
    # sum_{t=0..power-1} (start+t) = power*(2*start + power - 1)/2
    let two: i64 = modmul(2, start) 
    let inner: i64 = (two + (power % MOD) - 1) % MOD
    if inner < 0 { inner = inner + MOD }
    # /2 mod MOD
    return modmul(modmul(power, inner), (MOD + 1) / 2)
}

function M(n: i64, a: i64, b: i64, c: i64, i: i64) -> i64 {
    if n <= 0 { return 0 }
    let mut power: i64 = 1
    let mut e: i64 = 0
    while e < i {
        power = power * 4
        e = e + 1
    }
    if power < n {
        return (M(power, a, b, c, i) + M(n - power, 4 * a, 4 * b, 4 * c, i + 1)) % MOD
    } elif power == n {
        return (block_sum(a, power) + block_sum(b, power) + block_sum(c, power)) % MOD
    } else {
        let s_power: i64 = power / 4
        let mut n1: i64 = n
        if n1 > s_power { n1 = s_power }
        let sum_1: i64 = M(n1, a, b, c, i - 1) % MOD
        let mut n2: i64 = n - s_power
        if n2 > s_power { n2 = s_power }
        let sum_2: i64 = M(n2, a + s_power, b + 2 * s_power, c + 3 * s_power, i - 1) % MOD
        let mut n3: i64 = n - 2 * s_power
        if n3 > s_power { n3 = s_power }
        let sum_3: i64 = M(n3, a + 2 * s_power, b + 3 * s_power, c + s_power, i - 1) % MOD
        let mut n4: i64 = n - 3 * s_power
        if n4 > s_power { n4 = s_power }
        let sum_4: i64 = M(n4, a + 3 * s_power, b + s_power, c + 2 * s_power, i - 1) % MOD
        return (sum_1 + sum_2 + sum_3 + sum_4) % MOD
    }
}

function main() -> i32 {
    printf("%lld\n", M(1000000000000000000, 1, 2, 3, 0))
    return 0
}

Generated C

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

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

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

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

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

#include <math.h>

void* _ui_state = NULL;

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

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

int64_t modmul_i64_i64(int64_t a, int64_t b);
int64_t block_sum_i64_i64(int64_t start, int64_t power);
int64_t M_i64_i64_i64_i64_i64(int64_t n, int64_t a, int64_t b, int64_t c, int64_t i);
int32_t main(void);

static const int64_t MOD = 1000000007;

int64_t modmul_i64_i64(int64_t a, int64_t b) {
    int64_t x = FLOW_CHECKED_MOD((a), (MOD));
    int64_t y = FLOW_CHECKED_MOD((b), (MOD));
    int64_t r = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(x)) * ((__int128)(y)))), (((__int128)(MOD))))));
    if (r < 0) {
        r = (r + MOD);
    }
    return r;
}

int64_t block_sum_i64_i64(int64_t start, int64_t power) {
    int64_t two = modmul_i64_i64(2, start);
    int64_t inner = FLOW_CHECKED_MOD((((two + FLOW_CHECKED_MOD((power), (MOD))) - 1)), (MOD));
    if (inner < 0) {
        inner = (inner + MOD);
    }
    return modmul_i64_i64(modmul_i64_i64(power, inner), FLOW_CHECKED_DIV(((MOD + 1)), (2)));
}

int64_t M_i64_i64_i64_i64_i64(int64_t n, int64_t a, int64_t b, int64_t c, int64_t i) {
    if (n <= 0) {
        return 0;
    }
    int64_t power = 1;
    int64_t e = 0;
    while (e < i) {
        power = (power * 4);
        e = (e + 1);
    }
    if (power < n) {
        return FLOW_CHECKED_MOD(((M_i64_i64_i64_i64_i64(power, a, b, c, i) + M_i64_i64_i64_i64_i64((n - power), (4 * a), (4 * b), (4 * c), (i + 1)))), (MOD));
    } else if (power == n) {
        return FLOW_CHECKED_MOD((((block_sum_i64_i64(a, power) + block_sum_i64_i64(b, power)) + block_sum_i64_i64(c, power))), (MOD));
    } else {
        int64_t s_power = FLOW_CHECKED_DIV((power), (4));
        int64_t n1 = n;
        if (n1 > s_power) {
            n1 = s_power;
        }
        int64_t sum_1 = FLOW_CHECKED_MOD((M_i64_i64_i64_i64_i64(n1, a, b, c, (i - 1))), (MOD));
        int64_t n2 = (n - s_power);
        if (n2 > s_power) {
            n2 = s_power;
        }
        int64_t sum_2 = FLOW_CHECKED_MOD((M_i64_i64_i64_i64_i64(n2, (a + s_power), (b + (2 * s_power)), (c + (3 * s_power)), (i - 1))), (MOD));
        int64_t n3 = (n - (2 * s_power));
        if (n3 > s_power) {
            n3 = s_power;
        }
        int64_t sum_3 = FLOW_CHECKED_MOD((M_i64_i64_i64_i64_i64(n3, (a + (2 * s_power)), (b + (3 * s_power)), (c + s_power), (i - 1))), (MOD));
        int64_t n4 = (n - (3 * s_power));
        if (n4 > s_power) {
            n4 = s_power;
        }
        int64_t sum_4 = FLOW_CHECKED_MOD((M_i64_i64_i64_i64_i64(n4, (a + (3 * s_power)), (b + s_power), (c + (2 * s_power)), (i - 1))), (MOD));
        return FLOW_CHECKED_MOD(((((sum_1 + sum_2) + sum_3) + sum_4)), (MOD));
    }
}

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