Problem 359

Hilbert's Hotel: sum P(2^a * 3^b, 2^{27-a}*3^{12-b}) mod 10^8.

Answer40632119
Output40632119
StatusPASS
Native helperno
Runtime0 ms
Peak memory1072 KB
Time complexityO(n^2) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n log n)
Space complexityO(1)O(n)
ApproachFlow solutionModular DP or matrix exponentiation
VerdictSuboptimal

Flow source

# Project Euler 359
# Hilbert's Hotel: sum P(2^a * 3^b, 2^{27-a}*3^{12-b}) mod 10^8.

function mulmod(a: i64, b: i64, mod: i64) -> i64 {
    # (a * b) % mod with a,b reduced; uses i128 via double-and-add for safety
    let mut x: i64 = a % mod
    if x < 0 { x = x + mod }
    let mut y: i64 = b % mod
    if y < 0 { y = y + mod }
    let mut res: i64 = 0
    while y > 0 {
        if y % 2 == 1 {
            res = res + x
            if res >= mod { res = res - mod }
        }
        x = x + x
        if x >= mod { x = x - mod }
        y = y / 2
    }
    return res
}

function p_value(floor: i64, room: i64, mod: i64) -> i64 {
    # result = ((floor+1)//2)*floor  [- (floor+1)//2 if floor odd > 1]
    let half: i64 = (floor + 1) / 2
    let mut result: i64 = mulmod(half, floor, mod)
    if floor % 2 == 1 && floor > 1 {
        result = result - (half % mod)
        if result < 0 { result = result + mod }
    }

    let mut increment_even: i64 = 1
    if floor % 2 == 0 {
        increment_even = 2 * floor + 1
    }
    let mut increment_odd: i64 = 2
    if floor % 2 == 1 {
        increment_odd = 2 * floor
    }
    if floor == 1 {
        increment_odd = 3
        increment_even = 2
    }

    let num_even: i64 = room / 2
    let num_odd: i64 = (room - 1) / 2

    # triangle_even*2 cancelled: num_even*(num_even+1)
    # triangle_odd*2 cancelled: num_odd*(num_odd+1)
    let te: i64 = mulmod(num_even, num_even + 1, mod)
    let tod: i64 = mulmod(num_odd, num_odd + 1, mod)

    let ie: i64 = increment_even - 2
    let io: i64 = increment_odd - 2

    result = (result + mulmod(num_even, ie, mod)) % mod
    if result < 0 { result = result + mod }
    result = (result + te) % mod
    result = (result + mulmod(num_odd, io, mod)) % mod
    if result < 0 { result = result + mod }
    result = (result + tod) % mod
    return result
}

function main() -> i32 {
    let mod: i64 = 100000000
    let number: i64 = 134217728  # 2^27
    number = number * 531441     # * 3^12

    let mut total: i64 = 0
    let mut two: i64 = 1
    let mut a: i32 = 0
    while a <= 27 {
        let mut three: i64 = 1
        let mut b: i32 = 0
        while b <= 12 {
            let floor: i64 = two * three
            let room: i64 = number / floor
            total = (total + p_value(floor, room, mod)) % mod
            three = three * 3
            b = b + 1
        }
        two = two * 2
        a = a + 1
    }

    printf("%lld\n", total)
    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 mulmod_i64_i64_i64(int64_t a, int64_t b, int64_t mod);
int64_t p_value_i64_i64_i64(int64_t floor, int64_t room, int64_t mod);
int32_t main(void);

int64_t mulmod_i64_i64_i64(int64_t a, int64_t b, int64_t mod) {
    int64_t x = FLOW_CHECKED_MOD((a), (mod));
    if (x < 0) {
        x = (x + mod);
    }
    int64_t y = FLOW_CHECKED_MOD((b), (mod));
    if (y < 0) {
        y = (y + mod);
    }
    int64_t res = 0;
    while (y > 0) {
        if (FLOW_CHECKED_MOD((y), (2)) == 1) {
            res = (res + x);
            if (res >= mod) {
                res = (res - mod);
            }
        }
        x = (x + x);
        if (x >= mod) {
            x = (x - mod);
        }
        y = FLOW_CHECKED_DIV((y), (2));
    }
    return res;
}

int64_t p_value_i64_i64_i64(int64_t floor, int64_t room, int64_t mod) {
    int64_t half = FLOW_CHECKED_DIV(((floor + 1)), (2));
    int64_t result = mulmod_i64_i64_i64(half, floor, mod);
    if ((FLOW_CHECKED_MOD((floor), (2)) == 1 && floor > 1)) {
        result = (result - FLOW_CHECKED_MOD((half), (mod)));
        if (result < 0) {
            result = (result + mod);
        }
    }
    int64_t increment_even = 1;
    if (FLOW_CHECKED_MOD((floor), (2)) == 0) {
        increment_even = ((2 * floor) + 1);
    }
    int64_t increment_odd = 2;
    if (FLOW_CHECKED_MOD((floor), (2)) == 1) {
        increment_odd = (2 * floor);
    }
    if (floor == 1) {
        increment_odd = 3;
        increment_even = 2;
    }
    int64_t num_even = FLOW_CHECKED_DIV((room), (2));
    int64_t num_odd = FLOW_CHECKED_DIV(((room - 1)), (2));
    int64_t te = mulmod_i64_i64_i64(num_even, (num_even + 1), mod);
    int64_t tod = mulmod_i64_i64_i64(num_odd, (num_odd + 1), mod);
    int64_t ie = (increment_even - 2);
    int64_t io = (increment_odd - 2);
    result = FLOW_CHECKED_MOD(((result + mulmod_i64_i64_i64(num_even, ie, mod))), (mod));
    if (result < 0) {
        result = (result + mod);
    }
    result = FLOW_CHECKED_MOD(((result + te)), (mod));
    result = FLOW_CHECKED_MOD(((result + mulmod_i64_i64_i64(num_odd, io, mod))), (mod));
    if (result < 0) {
        result = (result + mod);
    }
    result = FLOW_CHECKED_MOD(((result + tod)), (mod));
    return result;
}

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