Problem 718

n = 17^p*a + 19^p*b + 23^p*c with a,b,c >= 1 is reachable iff n - s lies in the numerical semigroup S = <17^p, 19^p, 23^p>, where s = 17^p + 19^p + 23^p. So G(p) = sum(1..s-1) plus, for each gap m of S, the value s + m. Gaps come from the Apery set of S modulo x = 17^p, computed with the Bocker-Liptak round-robin algorithm: one cyclic relaxation pass per remaining generator (valid here since the generators are pairwise coprime).

Answer228579116
Output228579116
StatusPASS
Native helperno
Runtime1030 ms
Peak memory189632 KB
Time complexityO(n) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)O(n * d)
Space complexityO(n)O(n)
ApproachFlow solutionExpression enumeration
VerdictUnknown

Flow source

# Project Euler 718: Unreachable Numbers
# n = 17^p*a + 19^p*b + 23^p*c with a,b,c >= 1 is reachable iff
# n - s lies in the numerical semigroup S = <17^p, 19^p, 23^p>,
# where s = 17^p + 19^p + 23^p. So G(p) = sum(1..s-1) plus, for each
# gap m of S, the value s + m. Gaps come from the Apery set of S
# modulo x = 17^p, computed with the Bocker-Liptak round-robin
# algorithm: one cyclic relaxation pass per remaining generator
# (valid here since the generators are pairwise coprime).

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

function ipow(b: i64, e: i64) -> i64 {
    let mut r: i64 = 1
    for i in 0..e {
        r = r * b
    }
    return r
}

function solve(p: i64, m: i64) -> i64 {
    let x: i64 = ipow(17, p)
    let y: i64 = ipow(19, p)
    let z: i64 = ipow(23, p)

    # ap[r] = smallest element of S congruent to r mod x
    let ap: ptr<i64> = calloc(x, 8)
    if ap == null {
        return -1
    }
    let inf: i64 = 4000000000000000000
    for i in 1..x {
        ap[i] = inf
    }
    ap[0] = 0

    # Round-robin pass for generator y, then z. Start each cycle at
    # residue 0, whose value 0 is the global minimum.
    let mut r: i64 = 0
    for i in 0..x {
        let nr: i64 = (r + y) % x
        let cand: i64 = ap[r] + y
        if cand < ap[nr] {
            ap[nr] = cand
        }
        r = nr
    }
    r = 0
    for i in 0..x {
        let nr: i64 = (r + z) % x
        let cand: i64 = ap[r] + z
        if cand < ap[nr] {
            ap[nr] = cand
        }
        r = nr
    }

    # Sum unreachable values modulo m. All n in 1..s-1 are unreachable,
    # then one unreachable value s + gap per gap of S. Residue class rr
    # contributes gaps rr, rr + x, ..., ap[rr] - x.
    let s: i64 = x + y + z
    let mut total: i64 = (s % m) * ((s - 1) % m) % m
    let inv2: i64 = (m + 1) / 2
    total = total * inv2 % m
    for rr in 0..x {
        let k: i64 = (ap[rr] - rr) / x
        if k > 0 {
            let tri: i64 = k * (k - 1) / 2
            let big: i128 = ((x as i128) * (tri as i128)) % (m as i128)
            let mut term: i64 = ((k % m) * (s % m)) % m
            term = (term + ((k % m) * (rr % m)) % m) % m
            term = (term + (big as i64)) % m
            total = (total + term) % m
        }
    }
    free(ap)
    return total
}

function main() -> i32 {
    printf("%lld\n", solve(6, 1000000007))
    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 ipow_i64_i64(int64_t b, int64_t e);
int64_t solve_i64_i64(int64_t p, int64_t m);
int32_t main(void);



int64_t ipow_i64_i64(int64_t b, int64_t e) {
    int64_t r = 1;
    int32_t __flow_step_1 = 1;
    for (int32_t i = 0; (0 <= e) ? i < e : i > e; i += (0 <= e) ? 1 : -1) {
        r = (r * b);
    }
    return r;
}

int64_t solve_i64_i64(int64_t p, int64_t m) {
    int64_t x = ipow_i64_i64(17, p);
    int64_t y = ipow_i64_i64(19, p);
    int64_t z = ipow_i64_i64(23, p);
    int64_t* ap = (int64_t*)(calloc(x, 8));
    if (ap == NULL) {
        return (-1);
    }
    int64_t inf = 4000000000000000000;
    int32_t __flow_step_2 = 1;
    for (int32_t i = 1; (1 <= x) ? i < x : i > x; i += (1 <= x) ? 1 : -1) {
        ap[i] = inf;
    }
    ap[0] = 0;
    int64_t r = 0;
    int32_t __flow_step_3 = 1;
    for (int32_t i = 0; (0 <= x) ? i < x : i > x; i += (0 <= x) ? 1 : -1) {
        int64_t nr = FLOW_CHECKED_MOD(((r + y)), (x));
        int64_t cand = (ap[r] + y);
        if (cand < ap[nr]) {
            ap[nr] = cand;
        }
        r = nr;
    }
    r = 0;
    int32_t __flow_step_4 = 1;
    for (int32_t i = 0; (0 <= x) ? i < x : i > x; i += (0 <= x) ? 1 : -1) {
        int64_t nr = FLOW_CHECKED_MOD(((r + z)), (x));
        int64_t cand = (ap[r] + z);
        if (cand < ap[nr]) {
            ap[nr] = cand;
        }
        r = nr;
    }
    int64_t s = ((x + y) + z);
    int64_t total = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((s), (m)) * FLOW_CHECKED_MOD(((s - 1)), (m)))), (m));
    int64_t inv2 = FLOW_CHECKED_DIV(((m + 1)), (2));
    total = FLOW_CHECKED_MOD(((total * inv2)), (m));
    int32_t __flow_step_5 = 1;
    for (int32_t rr = 0; (0 <= x) ? rr < x : rr > x; rr += (0 <= x) ? 1 : -1) {
        int64_t k = FLOW_CHECKED_DIV(((ap[rr] - rr)), (x));
        if (k > 0) {
            int64_t tri = FLOW_CHECKED_DIV(((k * (k - 1))), (2));
            __int128 big = FLOW_CHECKED_MOD(((((__int128)(x)) * ((__int128)(tri)))), (((__int128)(m))));
            int64_t term = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((k), (m)) * FLOW_CHECKED_MOD((s), (m)))), (m));
            term = FLOW_CHECKED_MOD(((term + FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((k), (m)) * FLOW_CHECKED_MOD((rr), (m)))), (m)))), (m));
            term = FLOW_CHECKED_MOD(((term + ((int64_t)(big)))), (m));
            total = FLOW_CHECKED_MOD(((total + term)), (m));
        }
    }
    free(ap);
    return total;
}

int32_t main(void) {
    printf("%lld\n", solve_i64_i64(6, 1000000007));
    return 0;
}

Generated MLIR

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