Problem 734

A Bit of Prime: T(1e6,999983) mod 1e9+7.

Answer557988060
Output557988060
StatusPASS
Native helperno
Runtime80 ms
Peak memory18512 KB
Time complexityO(n^3) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^3)?
Space complexityO(n)?
ApproachFlow solutionNot curated
VerdictUnknown

Flow source

# Project Euler 734
# A Bit of Prime: T(1e6,999983) mod 1e9+7.

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

const MOD: i64 = 1000000007

function modpow(b: i64, e: i64) -> i64 {
    let mut r: i64 = 1
    let mut bb: i64 = b % MOD
    let mut ee: i64 = e
    while ee > 0 {
        if ee % 2 == 1 {
            r = r * bb % MOD
        }
        bb = bb * bb % MOD
        ee = ee / 2
    }
    return r
}

function popcount(n: i32) -> i32 {
    let mut x: i32 = n
    let mut c: i32 = 0
    while x > 0 {
        c = c + 1
        x = x & (x - 1)
    }
    return c
}

function main() -> i32 {
    let n: i32 = 1000000
    let k: i64 = 999983
    let mut B: i32 = 0
    let mut t: i32 = n
    while t > 0 {
        B = B + 1
        t = t >> 1
    }
    let size: i32 = 1 << B

    let is_prime: ptr<i8> = calloc((n + 1) as i64, 1)
    memset(is_prime, 1, (n + 1) as i64)
    is_prime[0] = 0
    is_prime[1] = 0
    let mut p: i32 = 2
    while (p as i64) * (p as i64) <= (n as i64) {
        if is_prime[p] != 0 {
            let mut j: i32 = p * p
            while j <= n {
                is_prime[j] = 0
                j = j + p
            }
        }
        p = p + 1
    }

    let a: ptr<i64> = calloc(size as i64, 8)
    let s: ptr<i64> = calloc(size as i64, 8)
    let mut pp: i32 = 2
    while pp <= n {
        if is_prime[pp] != 0 {
            a[pp] = 1
            if popcount(pp) % 2 == 1 {
                s[pp] = 0 - 1
            } else {
                s[pp] = 1
            }
        }
        pp = pp + 1
    }

    let mut i: i32 = 0
    while i < B {
        let step: i32 = 1 << i
        let jump: i32 = step << 1
        let mut base: i32 = 0
        while base < size {
            let mut m: i32 = base + step
            while m < base + jump {
                a[m] = a[m] + a[m - step]
                m = m + 1
            }
            base = base + jump
        }
        i = i + 1
    }

    i = 0
    while i < B {
        let step: i32 = 1 << i
        let jump: i32 = step << 1
        let mut base: i32 = 0
        while base < size {
            let mut m: i32 = base
            while m < base + step {
                s[m] = s[m] + s[m + step]
                m = m + 1
            }
            base = base + jump
        }
        i = i + 1
    }

    let mut res: i64 = 0
    let mut m: i32 = 0
    while m <= n {
        if a[m] == 0 {
            m = m + 1
            continue
        }
        let val: i64 = modpow(a[m], k)
        let mut coeff: i64 = s[m]
        if popcount(m) % 2 == 1 {
            coeff = 0 - coeff
        }
        res = (res + val * coeff) % MOD
        m = m + 1
    }
    if res < 0 {
        res = res + MOD
    }
    printf("%lld\n", res)
    free(is_prime)
    free(a)
    free(s)
    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 modpow_i64_i64(int64_t b, int64_t e);
int32_t popcount_i32(int32_t n);
int32_t main(void);

static const int64_t MOD = 1000000007;




int64_t modpow_i64_i64(int64_t b, int64_t e) {
    int64_t r = 1;
    int64_t bb = FLOW_CHECKED_MOD((b), (MOD));
    int64_t ee = e;
    while (ee > 0) {
        if (FLOW_CHECKED_MOD((ee), (2)) == 1) {
            r = FLOW_CHECKED_MOD(((r * bb)), (MOD));
        }
        bb = FLOW_CHECKED_MOD(((bb * bb)), (MOD));
        ee = FLOW_CHECKED_DIV((ee), (2));
    }
    return r;
}

int32_t popcount_i32(int32_t n) {
    int32_t x = n;
    int32_t c = 0;
    while (x > 0) {
        c = (c + 1);
        x = (x & (x - 1));
    }
    return c;
}

int32_t main(void) {
    int32_t n = 1000000;
    int64_t k = 999983;
    int32_t B = 0;
    int32_t t = n;
    while (t > 0) {
        B = (B + 1);
        t = FLOW_CHECKED_SHR((t), (1));
    }
    int32_t size = FLOW_CHECKED_SHL((1), (B));
    int8_t* is_prime = (int8_t*)(calloc(((int64_t)((n + 1))), 1));
    memset(is_prime, 1, ((int64_t)((n + 1))));
    is_prime[0] = 0;
    is_prime[1] = 0;
    int32_t p = 2;
    while ((((int64_t)(p)) * ((int64_t)(p))) <= ((int64_t)(n))) {
        if (is_prime[p] != 0) {
            int32_t j = (p * p);
            while (j <= n) {
                is_prime[j] = 0;
                j = (j + p);
            }
        }
        p = (p + 1);
    }
    int64_t* a = (int64_t*)(calloc(((int64_t)(size)), 8));
    int64_t* s = (int64_t*)(calloc(((int64_t)(size)), 8));
    int32_t pp = 2;
    while (pp <= n) {
        if (is_prime[pp] != 0) {
            a[pp] = 1;
            if (FLOW_CHECKED_MOD((popcount_i32(pp)), (2)) == 1) {
                s[pp] = (0 - 1);
            } else {
                s[pp] = 1;
            }
        }
        pp = (pp + 1);
    }
    int32_t i = 0;
    while (i < B) {
        int32_t step = FLOW_CHECKED_SHL((1), (i));
        int32_t jump = FLOW_CHECKED_SHL((step), (1));
        int32_t base = 0;
        while (base < size) {
            int32_t m = (base + step);
            while (m < (base + jump)) {
                a[m] = (a[m] + a[(m - step)]);
                m = (m + 1);
            }
            base = (base + jump);
        }
        i = (i + 1);
    }
    i = 0;
    while (i < B) {
        int32_t step = FLOW_CHECKED_SHL((1), (i));
        int32_t jump = FLOW_CHECKED_SHL((step), (1));
        int32_t base = 0;
        while (base < size) {
            int32_t m = base;
            while (m < (base + step)) {
                s[m] = (s[m] + s[(m + step)]);
                m = (m + 1);
            }
            base = (base + jump);
        }
        i = (i + 1);
    }
    int64_t res = 0;
    int32_t m = 0;
    while (m <= n) {
        if (a[m] == 0) {
            m = (m + 1);
            continue;
        }
        int64_t val = modpow_i64_i64(a[m], k);
        int64_t coeff = s[m];
        if (FLOW_CHECKED_MOD((popcount_i32(m)), (2)) == 1) {
            coeff = (0 - coeff);
        }
        res = FLOW_CHECKED_MOD(((res + (val * coeff))), (MOD));
        m = (m + 1);
    }
    if (res < 0) {
        res = (res + MOD);
    }
    printf("%lld\n", res);
    free(is_prime);
    free(a);
    free(s);
    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 private @memset(!llvm.ptr, i32, i64) -> !llvm.ptr
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
  func.func @modpow(%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 = llvm.mlir.addressof @MOD : !llvm.ptr
    %5 = llvm.load %4 : !llvm.ptr -> i64
    %6 = arith.remsi %arg0, %5 : i64
    %7 = llvm.mlir.constant(1 : i64) : i64
    %8 = llvm.alloca %7 x i64 : (i64) -> !llvm.ptr
    llvm.store %6, %8 : i64, !llvm.ptr
    %9 = llvm.mlir.constant(1 : i64) : i64
    %10 = llvm.alloca %9 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %10 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %11 = llvm.load %10 : !llvm.ptr -> i64
    %12 = arith.constant 0 : i32
    %14 = arith.extsi %12 : i32 to i64
    %13 = arith.cmpi sgt, %11, %14 : i64
    cf.cond_br %13, ^bb1, ^bb2
    ^bb1:
      %15 = llvm.load %10 : !llvm.ptr -> i64
      %16 = arith.constant 2 : i32
      %18 = arith.extsi %16 : i32 to i64
      %17 = arith.remsi %15, %18 : i64
      %19 = arith.constant 1 : i32
      %21 = arith.extsi %19 : i32 to i64
      %20 = arith.cmpi eq, %17, %21 : i64
      cf.cond_br %20, ^bb3, ^bb4
      ^bb3:
        %22 = llvm.load %3 : !llvm.ptr -> i64
        %23 = llvm.load %8 : !llvm.ptr -> i64
        %24 = arith.muli %22, %23 : i64
        %25 = llvm.mlir.addressof @MOD : !llvm.ptr
        %26 = llvm.load %25 : !llvm.ptr -> i64
        %27 = arith.remsi %24, %26 : i64
        llvm.store %27, %3 : i64, !llvm.ptr
        cf.br ^bb5
      ^bb4:
        cf.br ^bb5
      ^bb5:
      %28 = llvm.load %8 : !llvm.ptr -> i64
      %29 = llvm.load %8 : !llvm.ptr -> i64
      %30 = arith.muli %28, %29 : i64
      %31 = llvm.mlir.addressof @MOD : !llvm.ptr
      %32 = llvm.load %31 : !llvm.ptr -> i64
      %33 = arith.remsi %30, %32 : i64
      llvm.store %33, %8 : i64, !llvm.ptr
      %34 = llvm.load %10 : !llvm.ptr -> i64
      %35 = arith.constant 2 : i32
      %37 = arith.extsi %35 : i32 to i64
      %36 = arith.divsi %34, %37 : i64
      llvm.store %36, %10 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %38 = llvm.load %3 : !llvm.ptr -> i64
    func.return %38 : i64
  }
  func.func @popcount(%arg0: i32) -> i32 {
    %39 = llvm.mlir.constant(1 : i64) : i64
    %40 = llvm.alloca %39 x i32 : (i64) -> !llvm.ptr
    llvm.store %arg0, %40 : i32, !llvm.ptr
    %41 = arith.constant 0 : i32
    %42 = llvm.mlir.constant(1 : i64) : i64
    %43 = llvm.alloca %42 x i32 : (i64) -> !llvm.ptr
    llvm.store %41, %43 : i32, !llvm.ptr
    cf.br ^bb6
    ^bb6:
    %44 = llvm.load %40 : !llvm.ptr -> i32
    %45 = arith.constant 0 : i32
    %46 = arith.cmpi sgt, %44, %45 : i32
    cf.cond_br %46, ^bb7, ^bb8
    ^bb7:
      %47 = llvm.load %43 : !llvm.ptr -> i32
      %48 = arith.constant 1 : i32
      %49 = arith.addi %47, %48 : i32
      llvm.store %49, %43 : i32, !llvm.ptr
      %50 = llvm.load %40 : !llvm.ptr -> i32
      %51 = llvm.load %40 : !llvm.ptr -> i32
      %52 = arith.constant 1 : i32
      %53 = arith.subi %51, %52 : i32
      %54 = arith.andi %50, %53 : i32
      llvm.store %54, %40 : i32, !llvm.ptr
      cf.br ^bb6
    ^bb8:
    %55 = llvm.load %43 : !llvm.ptr -> i32
    func.return %55 : i32
  }
  func.func @main() -> i32 {
    %56 = arith.constant 1000000 : i32
    %57 = arith.constant 999983 : i32
    %58 = arith.extsi %57 : i32 to i64
    %59 = arith.constant 0 : i32
    %60 = llvm.mlir.constant(1 : i64) : i64
    %61 = llvm.alloca %60 x i32 : (i64) -> !llvm.ptr
    llvm.store %59, %61 : i32, !llvm.ptr
    %62 = llvm.mlir.constant(1 : i64) : i64
    %63 = llvm.alloca %62 x i32 : (i64) -> !llvm.ptr
    llvm.store %56, %63 : i32, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %64 = llvm.load %63 : !llvm.ptr -> i32
    %65 = arith.constant 0 : i32
    %66 = arith.cmpi sgt, %64, %65 : i32
    cf.cond_br %66, ^bb10, ^bb11
    ^bb10:
      %67 = llvm.load %61 : !llvm.ptr -> i32
      %68 = arith.constant 1 : i32
      %69 = arith.addi %67, %68 : i32
      llvm.store %69, %61 : i32, !llvm.ptr
      %70 = llvm.load %63 : !llvm.ptr -> i32
      %71 = arith.constant 1 : i32
      %72 = arith.shrsi %70, %71 : i32
      llvm.store %72, %63 : i32, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %73 = arith.constant 1 : i32
    %74 = llvm.load %61 : !llvm.ptr -> i32
    %75 = arith.shli %73, %74 : i32
    %77 = arith.constant 1 : i32
    %78 = arith.addi %56, %77 : i32
    %79 = arith.extsi %78 : i32 to i64
    %80 = arith.constant 1 : i32
    %81 = arith.extsi %80 : i32 to i64
    %76 = func.call @calloc(%79, %81) : (i64, i64) -> !llvm.ptr
    %83 = arith.constant 1 : i32
    %84 = arith.constant 1 : i32
    %85 = arith.addi %56, %84 : i32
    %86 = arith.extsi %85 : i32 to i64
    %82 = func.call @memset(%76, %83, %86) : (!llvm.ptr, i32, i64) -> !llvm.ptr
    %87 = arith.constant 0 : i32
    %88 = arith.constant 0 : i32
    %89 = arith.trunci %87 : i32 to i8
    %90 = arith.extsi %88 : i32 to i64
    %91 = llvm.getelementptr %76[%90] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %89, %91 : i8, !llvm.ptr
    %92 = arith.constant 0 : i32
    %93 = arith.constant 1 : i32
    %94 = arith.trunci %92 : i32 to i8
    %95 = arith.extsi %93 : i32 to i64
    %96 = llvm.getelementptr %76[%95] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %94, %96 : i8, !llvm.ptr
    %97 = arith.constant 2 : i32
    %98 = llvm.mlir.constant(1 : i64) : i64
    %99 = llvm.alloca %98 x i32 : (i64) -> !llvm.ptr
    llvm.store %97, %99 : i32, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %100 = llvm.load %99 : !llvm.ptr -> i32
    %101 = arith.extsi %100 : i32 to i64
    %102 = llvm.load %99 : !llvm.ptr -> i32
    %103 = arith.extsi %102 : i32 to i64
    %104 = arith.muli %101, %103 : i64
    %105 = arith.extsi %56 : i32 to i64
    %106 = arith.cmpi sle, %104, %105 : i64
    cf.cond_br %106, ^bb13, ^bb14
    ^bb13:
      %108 = llvm.load %99 : !llvm.ptr -> i32
      %109 = arith.extsi %108 : i32 to i64
      %110 = llvm.getelementptr %76[%109] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %107 = llvm.load %110 : !llvm.ptr -> i8
      %111 = arith.constant 0 : i32
      %113 = arith.extsi %107 : i8 to i32
      %112 = arith.cmpi ne, %113, %111 : i32
      cf.cond_br %112, ^bb15, ^bb16
      ^bb15:
        %114 = llvm.load %99 : !llvm.ptr -> i32
        %115 = llvm.load %99 : !llvm.ptr -> i32
        %116 = arith.muli %114, %115 : i32
        %117 = llvm.mlir.constant(1 : i64) : i64
        %118 = llvm.alloca %117 x i32 : (i64) -> !llvm.ptr
        llvm.store %116, %118 : i32, !llvm.ptr
        cf.br ^bb18
        ^bb18:
        %119 = llvm.load %118 : !llvm.ptr -> i32
        %120 = arith.cmpi sle, %119, %56 : i32
        cf.cond_br %120, ^bb19, ^bb20
        ^bb19:
          %121 = arith.constant 0 : i32
          %122 = llvm.load %118 : !llvm.ptr -> i32
          %123 = arith.trunci %121 : i32 to i8
          %124 = arith.extsi %122 : i32 to i64
          %125 = llvm.getelementptr %76[%124] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %123, %125 : i8, !llvm.ptr
          %126 = llvm.load %118 : !llvm.ptr -> i32
          %127 = llvm.load %99 : !llvm.ptr -> i32
          %128 = arith.addi %126, %127 : i32
          llvm.store %128, %118 : i32, !llvm.ptr
          cf.br ^bb18
        ^bb20:
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %129 = llvm.load %99 : !llvm.ptr -> i32
      %130 = arith.constant 1 : i32
      %131 = arith.addi %129, %130 : i32
      llvm.store %131, %99 : i32, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %133 = arith.extsi %75 : i32 to i64
    %134 = arith.constant 8 : i32
    %135 = arith.extsi %134 : i32 to i64
    %132 = func.call @calloc(%133, %135) : (i64, i64) -> !llvm.ptr
    %137 = arith.extsi %75 : i32 to i64
    %138 = arith.constant 8 : i32
    %139 = arith.extsi %138 : i32 to i64
    %136 = func.call @calloc(%137, %139) : (i64, i64) -> !llvm.ptr
    %140 = arith.constant 2 : i32
    %141 = llvm.mlir.constant(1 : i64) : i64
    %142 = llvm.alloca %141 x i32 : (i64) -> !llvm.ptr
    llvm.store %140, %142 : i32, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %143 = llvm.load %142 : !llvm.ptr -> i32
    %144 = arith.cmpi sle, %143, %56 : i32
    cf.cond_br %144, ^bb22, ^bb23
    ^bb22:
      %146 = llvm.load %142 : !llvm.ptr -> i32
      %147 = arith.extsi %146 : i32 to i64
      %148 = llvm.getelementptr %76[%147] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %145 = llvm.load %148 : !llvm.ptr -> i8
      %149 = arith.constant 0 : i32
      %151 = arith.extsi %145 : i8 to i32
      %150 = arith.cmpi ne, %151, %149 : i32
      cf.cond_br %150, ^bb24, ^bb25
      ^bb24:
        %152 = arith.constant 1 : i32
        %153 = llvm.load %142 : !llvm.ptr -> i32
        %154 = arith.extsi %152 : i32 to i64
        %155 = arith.extsi %153 : i32 to i64
        %156 = llvm.getelementptr %132[%155] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %154, %156 : i64, !llvm.ptr
        %158 = llvm.load %142 : !llvm.ptr -> i32
        %157 = func.call @popcount(%158) : (i32) -> i32
        %159 = arith.constant 2 : i32
        %160 = arith.remsi %157, %159 : i32
        %161 = arith.constant 1 : i32
        %162 = arith.cmpi eq, %160, %161 : i32
        cf.cond_br %162, ^bb27, ^bb28
        ^bb27:
          %163 = arith.constant 0 : i32
          %164 = arith.constant 1 : i32
          %165 = arith.subi %163, %164 : i32
          %166 = llvm.load %142 : !llvm.ptr -> i32
          %167 = arith.extsi %165 : i32 to i64
          %168 = arith.extsi %166 : i32 to i64
          %169 = llvm.getelementptr %136[%168] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %167, %169 : i64, !llvm.ptr
          cf.br ^bb29
        ^bb28:
          %170 = arith.constant 1 : i32
          %171 = llvm.load %142 : !llvm.ptr -> i32
          %172 = arith.extsi %170 : i32 to i64
          %173 = arith.extsi %171 : i32 to i64
          %174 = llvm.getelementptr %136[%173] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %172, %174 : i64, !llvm.ptr
          cf.br ^bb29
        ^bb29:
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %175 = llvm.load %142 : !llvm.ptr -> i32
      %176 = arith.constant 1 : i32
      %177 = arith.addi %175, %176 : i32
      llvm.store %177, %142 : i32, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %178 = arith.constant 0 : i32
    %179 = llvm.mlir.constant(1 : i64) : i64
    %180 = llvm.alloca %179 x i32 : (i64) -> !llvm.ptr
    llvm.store %178, %180 : i32, !llvm.ptr
    cf.br ^bb30
    ^bb30:
    %181 = llvm.load %180 : !llvm.ptr -> i32
    %182 = llvm.load %61 : !llvm.ptr -> i32
    %183 = arith.cmpi slt, %181, %182 : i32
    cf.cond_br %183, ^bb31, ^bb32
    ^bb31:
      %184 = arith.constant 1 : i32
      %185 = llvm.load %180 : !llvm.ptr -> i32
      %186 = arith.shli %184, %185 : i32
      %187 = arith.constant 1 : i32
      %188 = arith.shli %186, %187 : i32
      %189 = arith.constant 0 : i32
      %190 = llvm.mlir.constant(1 : i64) : i64
      %191 = llvm.alloca %190 x i32 : (i64) -> !llvm.ptr
      llvm.store %189, %191 : i32, !llvm.ptr
      cf.br ^bb33
      ^bb33:
      %192 = llvm.load %191 : !llvm.ptr -> i32
      %193 = arith.cmpi slt, %192, %75 : i32
      cf.cond_br %193, ^bb34, ^bb35
      ^bb34:
        %194 = llvm.load %191 : !llvm.ptr -> i32
        %195 = arith.addi %194, %186 : i32
        %196 = llvm.mlir.constant(1 : i64) : i64
        %197 = llvm.alloca %196 x i32 : (i64) -> !llvm.ptr
        llvm.store %195, %197 : i32, !llvm.ptr
        cf.br ^bb36
        ^bb36:
        %198 = llvm.load %197 : !llvm.ptr -> i32
        %199 = llvm.load %191 : !llvm.ptr -> i32
        %200 = arith.addi %199, %188 : i32
        %201 = arith.cmpi slt, %198, %200 : i32
        cf.cond_br %201, ^bb37, ^bb38
        ^bb37:
          %203 = llvm.load %197 : !llvm.ptr -> i32
          %204 = arith.extsi %203 : i32 to i64
          %205 = llvm.getelementptr %132[%204] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %202 = llvm.load %205 : !llvm.ptr -> i64
          %207 = llvm.load %197 : !llvm.ptr -> i32
          %208 = arith.subi %207, %186 : i32
          %209 = arith.extsi %208 : i32 to i64
          %210 = llvm.getelementptr %132[%209] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %206 = llvm.load %210 : !llvm.ptr -> i64
          %211 = arith.addi %202, %206 : i64
          %212 = llvm.load %197 : !llvm.ptr -> i32
          %213 = arith.extsi %212 : i32 to i64
          %214 = llvm.getelementptr %132[%213] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %211, %214 : i64, !llvm.ptr
          %215 = llvm.load %197 : !llvm.ptr -> i32
          %216 = arith.constant 1 : i32
          %217 = arith.addi %215, %216 : i32
          llvm.store %217, %197 : i32, !llvm.ptr
          cf.br ^bb36
        ^bb38:
        %218 = llvm.load %191 : !llvm.ptr -> i32
        %219 = arith.addi %218, %188 : i32
        llvm.store %219, %191 : i32, !llvm.ptr
        cf.br ^bb33
      ^bb35:
      %220 = llvm.load %180 : !llvm.ptr -> i32
      %221 = arith.constant 1 : i32
      %222 = arith.addi %220, %221 : i32
      llvm.store %222, %180 : i32, !llvm.ptr
      cf.br ^bb30
    ^bb32:
    %223 = arith.constant 0 : i32
    llvm.store %223, %180 : i32, !llvm.ptr
    cf.br ^bb39
    ^bb39:
    %224 = llvm.load %180 : !llvm.ptr -> i32
    %225 = llvm.load %61 : !llvm.ptr -> i32
    %226 = arith.cmpi slt, %224, %225 : i32
    cf.cond_br %226, ^bb40, ^bb41
    ^bb40:
      %227 = arith.constant 1 : i32
      %228 = llvm.load %180 : !llvm.ptr -> i32
      %229 = arith.shli %227, %228 : i32
      %230 = arith.constant 1 : i32
      %231 = arith.shli %229, %230 : i32
      %232 = arith.constant 0 : i32
      %233 = llvm.mlir.constant(1 : i64) : i64
      %234 = llvm.alloca %233 x i32 : (i64) -> !llvm.ptr
      llvm.store %232, %234 : i32, !llvm.ptr
      cf.br ^bb42
      ^bb42:
      %235 = llvm.load %234 : !llvm.ptr -> i32
      %236 = arith.cmpi slt, %235, %75 : i32
      cf.cond_br %236, ^bb43, ^bb44
      ^bb43:
        %237 = llvm.load %234 : !llvm.ptr -> i32
        %238 = llvm.mlir.constant(1 : i64) : i64
        %239 = llvm.alloca %238 x i32 : (i64) -> !llvm.ptr
        llvm.store %237, %239 : i32, !llvm.ptr
        cf.br ^bb45
        ^bb45:
        %240 = llvm.load %239 : !llvm.ptr -> i32
        %241 = llvm.load %234 : !llvm.ptr -> i32
        %242 = arith.addi %241, %229 : i32
        %243 = arith.cmpi slt, %240, %242 : i32
        cf.cond_br %243, ^bb46, ^bb47
        ^bb46:
          %245 = llvm.load %239 : !llvm.ptr -> i32
          %246 = arith.extsi %245 : i32 to i64
          %247 = llvm.getelementptr %136[%246] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %244 = llvm.load %247 : !llvm.ptr -> i64
          %249 = llvm.load %239 : !llvm.ptr -> i32
          %250 = arith.addi %249, %229 : i32
          %251 = arith.extsi %250 : i32 to i64
          %252 = llvm.getelementptr %136[%251] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %248 = llvm.load %252 : !llvm.ptr -> i64
          %253 = arith.addi %244, %248 : i64
          %254 = llvm.load %239 : !llvm.ptr -> i32
          %255 = arith.extsi %254 : i32 to i64
          %256 = llvm.getelementptr %136[%255] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %253, %256 : i64, !llvm.ptr
          %257 = llvm.load %239 : !llvm.ptr -> i32
          %258 = arith.constant 1 : i32
          %259 = arith.addi %257, %258 : i32
          llvm.store %259, %239 : i32, !llvm.ptr
          cf.br ^bb45
        ^bb47:
        %260 = llvm.load %234 : !llvm.ptr -> i32
        %261 = arith.addi %260, %231 : i32
        llvm.store %261, %234 : i32, !llvm.ptr
        cf.br ^bb42
      ^bb44:
      %262 = llvm.load %180 : !llvm.ptr -> i32
      %263 = arith.constant 1 : i32
      %264 = arith.addi %262, %263 : i32
      llvm.store %264, %180 : i32, !llvm.ptr
      cf.br ^bb39
    ^bb41:
    %265 = arith.constant 0 : i32
    %266 = arith.extsi %265 : i32 to i64
    %267 = llvm.mlir.constant(1 : i64) : i64
    %268 = llvm.alloca %267 x i64 : (i64) -> !llvm.ptr
    llvm.store %266, %268 : i64, !llvm.ptr
    %269 = arith.constant 0 : i32
    %270 = llvm.mlir.constant(1 : i64) : i64
    %271 = llvm.alloca %270 x i32 : (i64) -> !llvm.ptr
    llvm.store %269, %271 : i32, !llvm.ptr
    cf.br ^bb48
    ^bb48:
    %272 = llvm.load %271 : !llvm.ptr -> i32
    %273 = arith.cmpi sle, %272, %56 : i32
    cf.cond_br %273, ^bb49, ^bb50
    ^bb49:
      %275 = llvm.load %271 : !llvm.ptr -> i32
      %276 = arith.extsi %275 : i32 to i64
      %277 = llvm.getelementptr %132[%276] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %274 = llvm.load %277 : !llvm.ptr -> i64
      %278 = arith.constant 0 : i32
      %280 = arith.extsi %278 : i32 to i64
      %279 = arith.cmpi eq, %274, %280 : i64
      cf.cond_br %279, ^bb51, ^bb52
      ^bb51:
        %281 = llvm.load %271 : !llvm.ptr -> i32
        %282 = arith.constant 1 : i32
        %283 = arith.addi %281, %282 : i32
        llvm.store %283, %271 : i32, !llvm.ptr
        cf.br ^bb48
      ^bb52:
        cf.br ^bb53
      ^bb53:
      %286 = llvm.load %271 : !llvm.ptr -> i32
      %287 = arith.extsi %286 : i32 to i64
      %288 = llvm.getelementptr %132[%287] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %285 = llvm.load %288 : !llvm.ptr -> i64
      %284 = func.call @modpow(%285, %58) : (i64, i64) -> i64
      %290 = llvm.load %271 : !llvm.ptr -> i32
      %291 = arith.extsi %290 : i32 to i64
      %292 = llvm.getelementptr %136[%291] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %289 = llvm.load %292 : !llvm.ptr -> i64
      %293 = llvm.mlir.constant(1 : i64) : i64
      %294 = llvm.alloca %293 x i64 : (i64) -> !llvm.ptr
      llvm.store %289, %294 : i64, !llvm.ptr
      %296 = llvm.load %271 : !llvm.ptr -> i32
      %295 = func.call @popcount(%296) : (i32) -> i32
      %297 = arith.constant 2 : i32
      %298 = arith.remsi %295, %297 : i32
      %299 = arith.constant 1 : i32
      %300 = arith.cmpi eq, %298, %299 : i32
      cf.cond_br %300, ^bb54, ^bb55
      ^bb54:
        %301 = arith.constant 0 : i32
        %302 = llvm.load %294 : !llvm.ptr -> i64
        %304 = arith.extsi %301 : i32 to i64
        %303 = arith.subi %304, %302 : i64
        llvm.store %303, %294 : i64, !llvm.ptr
        cf.br ^bb56
      ^bb55:
        cf.br ^bb56
      ^bb56:
      %305 = llvm.load %268 : !llvm.ptr -> i64
      %306 = llvm.load %294 : !llvm.ptr -> i64
      %307 = arith.muli %284, %306 : i64
      %308 = arith.addi %305, %307 : i64
      %309 = llvm.mlir.addressof @MOD : !llvm.ptr
      %310 = llvm.load %309 : !llvm.ptr -> i64
      %311 = arith.remsi %308, %310 : i64
      llvm.store %311, %268 : i64, !llvm.ptr
      %312 = llvm.load %271 : !llvm.ptr -> i32
      %313 = arith.constant 1 : i32
      %314 = arith.addi %312, %313 : i32
      llvm.store %314, %271 : i32, !llvm.ptr
      cf.br ^bb48
    ^bb50:
    %315 = llvm.load %268 : !llvm.ptr -> i64
    %316 = arith.constant 0 : i32
    %318 = arith.extsi %316 : i32 to i64
    %317 = arith.cmpi slt, %315, %318 : i64
    cf.cond_br %317, ^bb57, ^bb58
    ^bb57:
      %319 = llvm.load %268 : !llvm.ptr -> i64
      %320 = llvm.mlir.addressof @MOD : !llvm.ptr
      %321 = llvm.load %320 : !llvm.ptr -> i64
      %322 = arith.addi %319, %321 : i64
      llvm.store %322, %268 : i64, !llvm.ptr
      cf.br ^bb59
    ^bb58:
      cf.br ^bb59
    ^bb59:
    %323 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %324 = llvm.load %268 : !llvm.ptr -> i64
    %325 = llvm.call @printf(%323, %324) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%76) : (!llvm.ptr) -> ()
    func.call @free(%132) : (!llvm.ptr) -> ()
    func.call @free(%136) : (!llvm.ptr) -> ()
    %329 = arith.constant 0 : i32
    func.return %329 : i32
  }
}