← All problems
Problem 639
S_k(n) = sum f_k(i) for i=1..n, f_k(p^e) = p^k Sum over k=1..50 of S_k(10^12) mod 10^9+7. Uses powerful number DFS + Stirling numbers for power sums.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n log n)O(n log n)
Space complexity O(n^2)O(n)
Approach Flow solution Modular DP or matrix exponentiation
Verdict Optimal
Flow source
# Project Euler 639: Summing a Multiplicative Function
# S_k(n) = sum f_k(i) for i=1..n, f_k(p^e) = p^k
# Sum over k=1..50 of S_k(10^12) mod 10^9+7.
# Uses powerful number DFS + Stirling numbers for power sums.
import euler.nt { isqrt }
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
function memset(s: ptr<void>, c: i64, n: i64) -> ptr<void>
}
const MOD: i64 = 1000000007
const KMAX: i64 = 50
const N_TARGET: i64 = 1000000000000 # 10^12
const MAX_PRECOMP: i64 = 1000000 # isqrt(10^12)
const STRIDE: i64 = MAX_PRECOMP + 1
# Global arrays for DFS
let mut g_n: i64 = 0
let mut g_m: i64 = 0
let mut g_primes: ptr<i64> = null
let mut g_p2: ptr<i64> = null
let mut g_c: ptr<i64> = null
let mut g_ans_k: i64 = 0
let mut g_ps32: ptr<i32> = null # power sum table (i32 array)
let mut g_coeff: ptr<i64> = null # Stirling coeff [k][j], flattened
let mut g_cache_keys: ptr<i64> = null
let mut g_cache_vals: ptr<i64> = null
let mut g_cache_count: i64 = 0
function power_sum_large(t: i64, k: i64, row: ptr<i64>) -> i64 {
# sum_{m=1..t} m^k mod MOD using falling factorial formula
# sum = sum_{j=1..k} S2(k,j)/(j+1) * (t+1)_{j+1}
let n_mod: i64 = t % MOD
let mut prod: i64 = (n_mod + 1) % MOD
let mut res: i64 = 0
for j in 1..(k + 1) {
let factor: i64 = (n_mod + 1 - j) % MOD
if factor < 0 { factor = factor + MOD }
prod = (prod * factor) % MOD
res = (res + row[j] * prod) % MOD
}
return res
}
function powsum(t: i64, k: i64, base: i64, row: ptr<i64>) -> i64 {
if t <= MAX_PRECOMP {
return g_ps32[base + t] as i64
}
# Hash-based cache: use t % HASH_SIZE as index
let h: i64 = t % 2000003
if g_cache_keys[h] == t { return g_cache_vals[h] }
let v: i64 = power_sum_large(t, k, row)
g_cache_keys[h] = t
g_cache_vals[h] = v
return v
}
function dfs(start_idx: i64, v: i64, w: i64, k: i64, base: i64, row: ptr<i64>) -> void {
g_ans_k = (g_ans_k + powsum(g_n / v, k, base, row) * w) % MOD
# Find last prime index where v * p2[i] <= g_n using binary search
# p2 is sorted ascending, so we need largest i with p2[i] <= g_n / v
let limit_val: i64 = g_n / v
let mut lo: i64 = start_idx
let mut hi: i64 = g_m
while lo < hi {
let mid: i64 = (lo + hi) / 2
if g_p2[mid] <= limit_val { lo = mid + 1 } else { hi = mid }
}
let end_idx: i64 = lo
for i in start_idx..end_idx {
let vv: i64 = v * g_p2[i]
let ww: i64 = (w * g_c[i]) % MOD
let p: i64 = g_primes[i]
let mut vvv: i64 = vv
while vvv <= g_n {
dfs(i + 1, vvv, ww, k, base, row)
if vvv > g_n / p { break }
vvv = vvv * p
}
}
}
function main() -> i32 {
let limit: i64 = isqrt(N_TARGET)
# Sieve primes up to limit
let is_comp: ptr<i64> = calloc(limit + 1, 8)
let primes: ptr<i64> = calloc(limit / 10 + 100, 8)
let mut m: i64 = 0
for i in 2..(limit + 1) {
if is_comp[i] == 0 {
primes[m] = i
m = m + 1
let mut j: i64 = (i as i64) * (i as i64)
while j <= limit {
is_comp[j] = 1
j = j + i
}
}
}
free(is_comp)
# p2[i] = primes[i]^2
let p2: ptr<i64> = calloc(m, 8)
for i in 0..m { p2[i] = primes[i] * primes[i] }
# Build Stirling numbers S2[n][k] and coeff[n][j] = S2[n][j] * inv(j+1)
# Flattened: S2[n*(KMAX+1)+k], coeff[n*(KMAX+1)+j]
let stirling: ptr<i64> = calloc((KMAX + 1) * (KMAX + 1), 8)
stirling[0] = 1 # S2[0][0] = 1
for n in 1..(KMAX + 1) {
for k in 1..(n + 1) {
stirling[n * (KMAX + 1) + k] = (stirling[(n - 1) * (KMAX + 1) + k - 1] + k * stirling[(n - 1) * (KMAX + 1) + k]) % MOD
}
}
# Modular inverses of 1..KMAX+1
let inv: ptr<i64> = calloc(KMAX + 2, 8)
inv[1] = 1
for i in 2..(KMAX + 2) {
inv[i] = (MOD - (MOD / i)) * inv[MOD % i] % MOD
}
let coeff: ptr<i64> = calloc((KMAX + 1) * (KMAX + 1), 8)
for n in 1..(KMAX + 1) {
for j in 1..(n + 1) {
coeff[n * (KMAX + 1) + j] = stirling[n * (KMAX + 1) + j] * inv[j + 1] % MOD
}
}
free(stirling)
# Build power sum table
let ps_size: i64 = (KMAX + 1) * STRIDE
let ps32: ptr<i32> = calloc(ps_size, 4)
if ps32 == null {
printf("Failed to allocate power sum table\n")
return 1
}
g_ps32 = ps32
for t in 1..STRIDE {
let x: i64 = t
let mut p: i64 = x
for k in 1..(KMAX + 1) {
let idx: i64 = k * STRIDE + t
let prev: i64 = ps32[idx - 1]
ps32[idx] = ((prev as i64 + p) % MOD) as i32
p = (p * x) % MOD
}
}
# Set up globals for DFS
g_n = N_TARGET
g_m = m
g_primes = primes
g_p2 = p2
# Cache for large powsum values (hash table)
let cache_size: i64 = 2000003
g_cache_keys = calloc(cache_size, 8)
g_cache_vals = calloc(cache_size, 8)
g_cache_count = 0
# c[i] = p^k - p^{2k} mod MOD, updated per k
let c: ptr<i64> = calloc(m, 8)
g_c = c
# pk[i] = p_i^k mod MOD
let pk_arr: ptr<i64> = calloc(m, 8)
for i in 0..m { pk_arr[i] = 1 }
let mut total: i64 = 0
for k in 1..(KMAX + 1) {
# Update pk and c
for i in 0..m {
let pkv: i64 = (pk_arr[i] * primes[i]) % MOD
pk_arr[i] = pkv
c[i] = (pkv - (pkv * pkv) % MOD) % MOD
if c[i] < 0 { c[i] = c[i] + MOD }
}
let base: i64 = k * STRIDE
let row: ptr<i64> = coeff + k * (KMAX + 1)
g_ans_k = 0
# Clear cache
memset(g_cache_keys as ptr<void>, 0, 2000003 * 8)
dfs(0, 1, 1, k, base, row)
total = (total + g_ans_k) % MOD
}
printf("%lld\n", total)
free(pk_arr)
free(c)
free(g_cache_vals)
free(g_cache_keys)
free(ps32)
free(coeff)
free(inv)
free(p2)
free(primes)
return 0
}
Generated C
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
while (flow_temp_head) {
flow_temp_node* n = flow_temp_head;
flow_temp_head = n->next;
free(n);
}
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
if (!node) return NULL;
node->next = flow_temp_head;
flow_temp_head = node;
if (!flow_temp_atexit_set) {
flow_temp_atexit_set = 1;
atexit(flow_temp_free_all);
}
return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
char* r = (char*)flow_temp_alloc(la + lb + 1);
if (!r) return NULL;
if (la) memcpy(r, a, la);
if (lb) memcpy(r + la, b, lb);
r[la + lb] = '\0';
return r;
}
#define __flow_in_arr(arr, val) __extension__ ({ \
int _found = 0; \
size_t _n = sizeof(arr)/sizeof((arr)[0]); \
for (size_t _i = 0; _i < _n; _i++) { \
if ((arr)[_i] == (val)) { _found = 1; break; } \
} _found; })
/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
abort();
#if defined(__GNUC__) || defined(__clang__)
__builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")
#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#include <math.h>
void* _ui_state = NULL;
static inline float i32_to_f32(int32_t v) { return (float)v; }
/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }
int64_t gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
int64_t power_sum_large_i64_i64_ptr_i64(int64_t t, int64_t k, int64_t* row);
int64_t powsum_i64_i64_i64_ptr_i64(int64_t t, int64_t k, int64_t base, int64_t* row);
void dfs_i64_i64_i64_i64_i64_ptr_i64(int64_t start_idx, int64_t v, int64_t w, int64_t k, int64_t base, int64_t* row);
int32_t main(void);
static const int64_t MOD = 1000000007;
static const int64_t KMAX = 50;
static const int64_t N_TARGET = 1000000000000;
static const int64_t MAX_PRECOMP = 1000000;
static const int64_t STRIDE = (MAX_PRECOMP + 1);
/* Module statics */
static int64_t g_n = 0;
static int64_t g_m = 0;
static int64_t* g_primes = NULL;
static int64_t* g_p2 = NULL;
static int64_t* g_c = NULL;
static int64_t g_ans_k = 0;
static int32_t* g_ps32 = NULL;
static int64_t* g_coeff = NULL;
static int64_t* g_cache_keys = NULL;
static int64_t* g_cache_vals = NULL;
static int64_t g_cache_count = 0;
int64_t gcd_i64_i64(int64_t a0, int64_t b0) {
int64_t a = a0;
int64_t b = b0;
while (b != 0) {
int64_t t = FLOW_CHECKED_MOD((a), (b));
a = b;
b = t;
}
return a;
}
int64_t lcm_i64_i64(int64_t a, int64_t b) {
if ((a == 0 || b == 0)) {
return 0;
}
return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}
int64_t isqrt_i64(int64_t n) {
if (n < 2) {
return n;
}
int64_t x = n;
int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
while (y < x) {
x = y;
y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
}
return x;
}
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
int64_t a = FLOW_CHECKED_MOD((a0), (mod));
int64_t b = FLOW_CHECKED_MOD((b0), (mod));
int64_t result = 0;
while (b > 0) {
if (FLOW_CHECKED_MOD((b), (2)) == 1) {
result = FLOW_CHECKED_MOD(((result + a)), (mod));
}
a = FLOW_CHECKED_MOD(((a * 2)), (mod));
b = FLOW_CHECKED_DIV((b), (2));
}
return result;
}
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
if (mod == 1) {
return 0;
}
int64_t result = 1;
int64_t b = FLOW_CHECKED_MOD((base), (mod));
int64_t e = exp;
while (e > 0) {
if (FLOW_CHECKED_MOD((e), (2)) == 1) {
result = mulmod_i64_i64_i64(result, b, mod);
}
b = mulmod_i64_i64_i64(b, b, mod);
e = FLOW_CHECKED_DIV((e), (2));
}
return result;
}
bool is_prime_i64(int64_t n) {
if (n < 2) {
return 0;
}
if (n < 4) {
return 1;
}
if ((FLOW_CHECKED_MOD((n), (2)) == 0 || FLOW_CHECKED_MOD((n), (3)) == 0)) {
return 0;
}
int64_t i = 5;
while ((i * i) <= n) {
if ((FLOW_CHECKED_MOD((n), (i)) == 0 || FLOW_CHECKED_MOD((n), ((i + 2))) == 0)) {
return 0;
}
i = (i + 6);
}
return 1;
}
int64_t power_sum_large_i64_i64_ptr_i64(int64_t t, int64_t k, int64_t* row) {
int64_t n_mod = FLOW_CHECKED_MOD((t), (MOD));
int64_t prod = FLOW_CHECKED_MOD(((n_mod + 1)), (MOD));
int64_t res = 0;
int32_t __flow_step_1 = 1;
for (int32_t j = 1; (1 <= (k + 1)) ? j < (k + 1) : j > (k + 1); j += (1 <= (k + 1)) ? 1 : -1) {
int64_t factor = FLOW_CHECKED_MOD((((n_mod + 1) - j)), (MOD));
if (factor < 0) {
factor = (factor + MOD);
}
prod = FLOW_CHECKED_MOD(((prod * factor)), (MOD));
res = FLOW_CHECKED_MOD(((res + (row[j] * prod))), (MOD));
}
return res;
}
int64_t powsum_i64_i64_i64_ptr_i64(int64_t t, int64_t k, int64_t base, int64_t* row) {
if (t <= MAX_PRECOMP) {
return ((int64_t)(g_ps32[(base + t)]));
}
int64_t h = FLOW_CHECKED_MOD((t), (2000003));
if (g_cache_keys[h] == t) {
return g_cache_vals[h];
}
int64_t v = power_sum_large_i64_i64_ptr_i64(t, k, row);
g_cache_keys[h] = t;
g_cache_vals[h] = v;
return v;
}
void dfs_i64_i64_i64_i64_i64_ptr_i64(int64_t start_idx, int64_t v, int64_t w, int64_t k, int64_t base, int64_t* row) {
g_ans_k = FLOW_CHECKED_MOD(((g_ans_k + (powsum_i64_i64_i64_ptr_i64(FLOW_CHECKED_DIV((g_n), (v)), k, base, row) * w))), (MOD));
int64_t limit_val = FLOW_CHECKED_DIV((g_n), (v));
int64_t lo = start_idx;
int64_t hi = g_m;
while (lo < hi) {
int64_t mid = FLOW_CHECKED_DIV(((lo + hi)), (2));
if (g_p2[mid] <= limit_val) {
lo = (mid + 1);
} else {
hi = mid;
}
}
int64_t end_idx = lo;
int32_t __flow_step_2 = 1;
for (int32_t i = start_idx; (start_idx <= end_idx) ? i < end_idx : i > end_idx; i += (start_idx <= end_idx) ? 1 : -1) {
int64_t vv = (v * g_p2[i]);
int64_t ww = FLOW_CHECKED_MOD(((w * g_c[i])), (MOD));
int64_t p = g_primes[i];
int64_t vvv = vv;
while (vvv <= g_n) {
dfs_i64_i64_i64_i64_i64_ptr_i64((i + 1), vvv, ww, k, base, row);
if (vvv > FLOW_CHECKED_DIV((g_n), (p))) {
break;
}
vvv = (vvv * p);
}
}
}
int32_t main(void) {
int64_t limit = isqrt_i64(N_TARGET);
int64_t* is_comp = (int64_t*)(calloc((limit + 1), 8));
int64_t* primes = (int64_t*)(calloc((FLOW_CHECKED_DIV((limit), (10)) + 100), 8));
int64_t m = 0;
int32_t __flow_step_3 = 1;
for (int32_t i = 2; (2 <= (limit + 1)) ? i < (limit + 1) : i > (limit + 1); i += (2 <= (limit + 1)) ? 1 : -1) {
if (is_comp[i] == 0) {
primes[m] = i;
m = (m + 1);
int64_t j = (((int64_t)(i)) * ((int64_t)(i)));
while (j <= limit) {
is_comp[j] = 1;
j = (j + i);
}
}
}
free(is_comp);
int64_t* p2 = (int64_t*)(calloc(m, 8));
int32_t __flow_step_4 = 1;
for (int32_t i = 0; (0 <= m) ? i < m : i > m; i += (0 <= m) ? 1 : -1) {
p2[i] = (primes[i] * primes[i]);
}
int64_t* stirling = (int64_t*)(calloc(((KMAX + 1) * (KMAX + 1)), 8));
stirling[0] = 1;
int32_t __flow_step_5 = 1;
for (int32_t n = 1; (1 <= (KMAX + 1)) ? n < (KMAX + 1) : n > (KMAX + 1); n += (1 <= (KMAX + 1)) ? 1 : -1) {
int32_t __flow_step_6 = 1;
for (int32_t k = 1; (1 <= (n + 1)) ? k < (n + 1) : k > (n + 1); k += (1 <= (n + 1)) ? 1 : -1) {
stirling[((n * (KMAX + 1)) + k)] = FLOW_CHECKED_MOD(((stirling[((((n - 1) * (KMAX + 1)) + k) - 1)] + (k * stirling[(((n - 1) * (KMAX + 1)) + k)]))), (MOD));
}
}
int64_t* inv = (int64_t*)(calloc((KMAX + 2), 8));
inv[1] = 1;
int32_t __flow_step_7 = 1;
for (int32_t i = 2; (2 <= (KMAX + 2)) ? i < (KMAX + 2) : i > (KMAX + 2); i += (2 <= (KMAX + 2)) ? 1 : -1) {
inv[i] = FLOW_CHECKED_MOD((((MOD - FLOW_CHECKED_DIV((MOD), (i))) * inv[FLOW_CHECKED_MOD((MOD), (i))])), (MOD));
}
int64_t* coeff = (int64_t*)(calloc(((KMAX + 1) * (KMAX + 1)), 8));
int32_t __flow_step_8 = 1;
for (int32_t n = 1; (1 <= (KMAX + 1)) ? n < (KMAX + 1) : n > (KMAX + 1); n += (1 <= (KMAX + 1)) ? 1 : -1) {
int32_t __flow_step_9 = 1;
for (int32_t j = 1; (1 <= (n + 1)) ? j < (n + 1) : j > (n + 1); j += (1 <= (n + 1)) ? 1 : -1) {
coeff[((n * (KMAX + 1)) + j)] = FLOW_CHECKED_MOD(((stirling[((n * (KMAX + 1)) + j)] * inv[(j + 1)])), (MOD));
}
}
free(stirling);
int64_t ps_size = ((KMAX + 1) * STRIDE);
int32_t* ps32 = (int32_t*)(calloc(ps_size, 4));
if (ps32 == NULL) {
printf("Failed to allocate power sum table\n");
return 1;
}
g_ps32 = ps32;
int32_t __flow_step_10 = 1;
for (int32_t t = 1; (1 <= STRIDE) ? t < STRIDE : t > STRIDE; t += (1 <= STRIDE) ? 1 : -1) {
int64_t x = t;
int64_t p = x;
int32_t __flow_step_11 = 1;
for (int32_t k = 1; (1 <= (KMAX + 1)) ? k < (KMAX + 1) : k > (KMAX + 1); k += (1 <= (KMAX + 1)) ? 1 : -1) {
int64_t idx = ((k * STRIDE) + t);
int64_t prev = ps32[(idx - 1)];
ps32[idx] = ((int32_t)(FLOW_CHECKED_MOD(((((int64_t)(prev)) + p)), (MOD))));
p = FLOW_CHECKED_MOD(((p * x)), (MOD));
}
}
g_n = N_TARGET;
g_m = m;
g_primes = primes;
g_p2 = p2;
int64_t cache_size = 2000003;
g_cache_keys = calloc(cache_size, 8);
g_cache_vals = calloc(cache_size, 8);
g_cache_count = 0;
int64_t* c = (int64_t*)(calloc(m, 8));
g_c = c;
int64_t* pk_arr = (int64_t*)(calloc(m, 8));
int32_t __flow_step_12 = 1;
for (int32_t i = 0; (0 <= m) ? i < m : i > m; i += (0 <= m) ? 1 : -1) {
pk_arr[i] = 1;
}
int64_t total = 0;
int32_t __flow_step_13 = 1;
for (int32_t k = 1; (1 <= (KMAX + 1)) ? k < (KMAX + 1) : k > (KMAX + 1); k += (1 <= (KMAX + 1)) ? 1 : -1) {
int32_t __flow_step_14 = 1;
for (int32_t i = 0; (0 <= m) ? i < m : i > m; i += (0 <= m) ? 1 : -1) {
int64_t pkv = FLOW_CHECKED_MOD(((pk_arr[i] * primes[i])), (MOD));
pk_arr[i] = pkv;
c[i] = FLOW_CHECKED_MOD(((pkv - FLOW_CHECKED_MOD(((pkv * pkv)), (MOD)))), (MOD));
if (c[i] < 0) {
c[i] = (c[i] + MOD);
}
}
int64_t base = (k * STRIDE);
int64_t* row = (int64_t*)((coeff + (k * (KMAX + 1))));
g_ans_k = 0;
memset(((void*)(g_cache_keys)), 0, (2000003 * 8));
dfs_i64_i64_i64_i64_i64_ptr_i64(0, 1, 1, k, base, row);
total = FLOW_CHECKED_MOD(((total + g_ans_k)), (MOD));
}
printf("%lld\n", total);
free(pk_arr);
free(c);
free(g_cache_vals);
free(g_cache_keys);
free(ps32);
free(coeff);
free(inv);
free(p2);
free(primes);
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("Failed to allocate power sum table\n\00") {addr_space = 0 : i32} : !llvm.array<36 x i8>
llvm.mlir.global internal constant @str_1("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
func.func @gcd(%arg0: i64, %arg1: i64) -> i64 {
%0 = llvm.mlir.constant(1 : i64) : i64
%1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %1 : i64, !llvm.ptr
%2 = llvm.mlir.constant(1 : i64) : i64
%3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %3 : i64, !llvm.ptr
cf.br ^bb0
^bb0:
%4 = llvm.load %3 : !llvm.ptr -> i64
%5 = arith.constant 0 : i32
%7 = arith.extsi %5 : i32 to i64
%6 = arith.cmpi ne, %4, %7 : i64
cf.cond_br %6, ^bb1, ^bb2
^bb1:
%8 = llvm.load %1 : !llvm.ptr -> i64
%9 = llvm.load %3 : !llvm.ptr -> i64
%10 = arith.remsi %8, %9 : i64
%11 = llvm.load %3 : !llvm.ptr -> i64
llvm.store %11, %1 : i64, !llvm.ptr
llvm.store %10, %3 : i64, !llvm.ptr
cf.br ^bb0
^bb2:
%12 = llvm.load %1 : !llvm.ptr -> i64
func.return %12 : i64
}
func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
%13 = arith.constant 0 : i32
%15 = arith.extsi %13 : i32 to i64
%14 = arith.cmpi eq, %arg0, %15 : i64
%16 = scf.if %14 -> (i1) {
%17 = arith.constant true
scf.yield %17 : i1
} else {
%18 = arith.constant 0 : i32
%20 = arith.extsi %18 : i32 to i64
%19 = arith.cmpi eq, %arg1, %20 : i64
scf.yield %19 : i1
}
cf.cond_br %16, ^bb3, ^bb4
^bb3:
%21 = arith.constant 0 : i32
%22 = arith.extsi %21 : i32 to i64
func.return %22 : i64
^bb4:
cf.br ^bb5
^bb5:
%23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
%24 = arith.divsi %arg0, %23 : i64
%25 = arith.muli %24, %arg1 : i64
func.return %25 : i64
}
func.func @isqrt(%arg0: i64) -> i64 {
%26 = arith.constant 2 : i32
%28 = arith.extsi %26 : i32 to i64
%27 = arith.cmpi slt, %arg0, %28 : i64
cf.cond_br %27, ^bb6, ^bb7
^bb6:
func.return %arg0 : i64
^bb7:
cf.br ^bb8
^bb8:
%29 = llvm.mlir.constant(1 : i64) : i64
%30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %30 : i64, !llvm.ptr
%31 = llvm.load %30 : !llvm.ptr -> i64
%32 = arith.constant 1 : i32
%34 = arith.extsi %32 : i32 to i64
%33 = arith.addi %31, %34 : i64
%35 = arith.constant 2 : i32
%37 = arith.extsi %35 : i32 to i64
%36 = arith.divsi %33, %37 : i64
%38 = llvm.mlir.constant(1 : i64) : i64
%39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
llvm.store %36, %39 : i64, !llvm.ptr
cf.br ^bb9
^bb9:
%40 = llvm.load %39 : !llvm.ptr -> i64
%41 = llvm.load %30 : !llvm.ptr -> i64
%42 = arith.cmpi slt, %40, %41 : i64
cf.cond_br %42, ^bb10, ^bb11
^bb10:
%43 = llvm.load %39 : !llvm.ptr -> i64
llvm.store %43, %30 : i64, !llvm.ptr
%44 = llvm.load %30 : !llvm.ptr -> i64
%45 = llvm.load %30 : !llvm.ptr -> i64
%46 = arith.divsi %arg0, %45 : i64
%47 = arith.addi %44, %46 : i64
%48 = arith.constant 2 : i32
%50 = arith.extsi %48 : i32 to i64
%49 = arith.divsi %47, %50 : i64
llvm.store %49, %39 : i64, !llvm.ptr
cf.br ^bb9
^bb11:
%51 = llvm.load %30 : !llvm.ptr -> i64
func.return %51 : i64
}
func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%52 = arith.remsi %arg0, %arg2 : i64
%53 = llvm.mlir.constant(1 : i64) : i64
%54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
llvm.store %52, %54 : i64, !llvm.ptr
%55 = arith.remsi %arg1, %arg2 : i64
%56 = llvm.mlir.constant(1 : i64) : i64
%57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
llvm.store %55, %57 : i64, !llvm.ptr
%58 = arith.constant 0 : i32
%59 = arith.extsi %58 : i32 to i64
%60 = llvm.mlir.constant(1 : i64) : i64
%61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
llvm.store %59, %61 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%62 = llvm.load %57 : !llvm.ptr -> i64
%63 = arith.constant 0 : i32
%65 = arith.extsi %63 : i32 to i64
%64 = arith.cmpi sgt, %62, %65 : i64
cf.cond_br %64, ^bb13, ^bb14
^bb13:
%66 = llvm.load %57 : !llvm.ptr -> i64
%67 = arith.constant 2 : i32
%69 = arith.extsi %67 : i32 to i64
%68 = arith.remsi %66, %69 : i64
%70 = arith.constant 1 : i32
%72 = arith.extsi %70 : i32 to i64
%71 = arith.cmpi eq, %68, %72 : i64
cf.cond_br %71, ^bb15, ^bb16
^bb15:
%73 = llvm.load %61 : !llvm.ptr -> i64
%74 = llvm.load %54 : !llvm.ptr -> i64
%75 = arith.addi %73, %74 : i64
%76 = arith.remsi %75, %arg2 : i64
llvm.store %76, %61 : i64, !llvm.ptr
cf.br ^bb17
^bb16:
cf.br ^bb17
^bb17:
%77 = llvm.load %54 : !llvm.ptr -> i64
%78 = arith.constant 2 : i32
%80 = arith.extsi %78 : i32 to i64
%79 = arith.muli %77, %80 : i64
%81 = arith.remsi %79, %arg2 : i64
llvm.store %81, %54 : i64, !llvm.ptr
%82 = llvm.load %57 : !llvm.ptr -> i64
%83 = arith.constant 2 : i32
%85 = arith.extsi %83 : i32 to i64
%84 = arith.divsi %82, %85 : i64
llvm.store %84, %57 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%86 = llvm.load %61 : !llvm.ptr -> i64
func.return %86 : i64
}
func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%87 = arith.constant 1 : i32
%89 = arith.extsi %87 : i32 to i64
%88 = arith.cmpi eq, %arg2, %89 : i64
cf.cond_br %88, ^bb18, ^bb19
^bb18:
%90 = arith.constant 0 : i32
%91 = arith.extsi %90 : i32 to i64
func.return %91 : i64
^bb19:
cf.br ^bb20
^bb20:
%92 = arith.constant 1 : i32
%93 = arith.extsi %92 : i32 to i64
%94 = llvm.mlir.constant(1 : i64) : i64
%95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
llvm.store %93, %95 : i64, !llvm.ptr
%96 = arith.remsi %arg0, %arg2 : i64
%97 = llvm.mlir.constant(1 : i64) : i64
%98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
llvm.store %96, %98 : i64, !llvm.ptr
%99 = llvm.mlir.constant(1 : i64) : i64
%100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %100 : i64, !llvm.ptr
cf.br ^bb21
^bb21:
%101 = llvm.load %100 : !llvm.ptr -> i64
%102 = arith.constant 0 : i32
%104 = arith.extsi %102 : i32 to i64
%103 = arith.cmpi sgt, %101, %104 : i64
cf.cond_br %103, ^bb22, ^bb23
^bb22:
%105 = llvm.load %100 : !llvm.ptr -> i64
%106 = arith.constant 2 : i32
%108 = arith.extsi %106 : i32 to i64
%107 = arith.remsi %105, %108 : i64
%109 = arith.constant 1 : i32
%111 = arith.extsi %109 : i32 to i64
%110 = arith.cmpi eq, %107, %111 : i64
cf.cond_br %110, ^bb24, ^bb25
^bb24:
%113 = llvm.load %95 : !llvm.ptr -> i64
%114 = llvm.load %98 : !llvm.ptr -> i64
%112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
llvm.store %112, %95 : i64, !llvm.ptr
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
%116 = llvm.load %98 : !llvm.ptr -> i64
%117 = llvm.load %98 : !llvm.ptr -> i64
%115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
llvm.store %115, %98 : i64, !llvm.ptr
%118 = llvm.load %100 : !llvm.ptr -> i64
%119 = arith.constant 2 : i32
%121 = arith.extsi %119 : i32 to i64
%120 = arith.divsi %118, %121 : i64
llvm.store %120, %100 : i64, !llvm.ptr
cf.br ^bb21
^bb23:
%122 = llvm.load %95 : !llvm.ptr -> i64
func.return %122 : i64
}
func.func @is_prime(%arg0: i64) -> i1 {
%123 = arith.constant 2 : i32
%125 = arith.extsi %123 : i32 to i64
%124 = arith.cmpi slt, %arg0, %125 : i64
cf.cond_br %124, ^bb27, ^bb28
^bb27:
%126 = arith.constant 0 : i1
func.return %126 : i1
^bb28:
cf.br ^bb29
^bb29:
%127 = arith.constant 4 : i32
%129 = arith.extsi %127 : i32 to i64
%128 = arith.cmpi slt, %arg0, %129 : i64
cf.cond_br %128, ^bb30, ^bb31
^bb30:
%130 = arith.constant 1 : i1
func.return %130 : i1
^bb31:
cf.br ^bb32
^bb32:
%131 = arith.constant 2 : i32
%133 = arith.extsi %131 : i32 to i64
%132 = arith.remsi %arg0, %133 : i64
%134 = arith.constant 0 : i32
%136 = arith.extsi %134 : i32 to i64
%135 = arith.cmpi eq, %132, %136 : i64
%137 = scf.if %135 -> (i1) {
%138 = arith.constant true
scf.yield %138 : i1
} else {
%139 = arith.constant 3 : i32
%141 = arith.extsi %139 : i32 to i64
%140 = arith.remsi %arg0, %141 : i64
%142 = arith.constant 0 : i32
%144 = arith.extsi %142 : i32 to i64
%143 = arith.cmpi eq, %140, %144 : i64
scf.yield %143 : i1
}
cf.cond_br %137, ^bb33, ^bb34
^bb33:
%145 = arith.constant 0 : i1
func.return %145 : i1
^bb34:
cf.br ^bb35
^bb35:
%146 = arith.constant 5 : i32
%147 = arith.extsi %146 : i32 to i64
%148 = llvm.mlir.constant(1 : i64) : i64
%149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
llvm.store %147, %149 : i64, !llvm.ptr
cf.br ^bb36
^bb36:
%150 = llvm.load %149 : !llvm.ptr -> i64
%151 = llvm.load %149 : !llvm.ptr -> i64
%152 = arith.muli %150, %151 : i64
%153 = arith.cmpi sle, %152, %arg0 : i64
cf.cond_br %153, ^bb37, ^bb38
^bb37:
%154 = llvm.load %149 : !llvm.ptr -> i64
%155 = arith.remsi %arg0, %154 : i64
%156 = arith.constant 0 : i32
%158 = arith.extsi %156 : i32 to i64
%157 = arith.cmpi eq, %155, %158 : i64
%159 = scf.if %157 -> (i1) {
%160 = arith.constant true
scf.yield %160 : i1
} else {
%161 = llvm.load %149 : !llvm.ptr -> i64
%162 = arith.constant 2 : i32
%164 = arith.extsi %162 : i32 to i64
%163 = arith.addi %161, %164 : i64
%165 = arith.remsi %arg0, %163 : i64
%166 = arith.constant 0 : i32
%168 = arith.extsi %166 : i32 to i64
%167 = arith.cmpi eq, %165, %168 : i64
scf.yield %167 : i1
}
cf.cond_br %159, ^bb39, ^bb40
^bb39:
%169 = arith.constant 0 : i1
func.return %169 : i1
^bb40:
cf.br ^bb41
^bb41:
%170 = llvm.load %149 : !llvm.ptr -> i64
%171 = arith.constant 6 : i32
%173 = arith.extsi %171 : i32 to i64
%172 = arith.addi %170, %173 : i64
llvm.store %172, %149 : i64, !llvm.ptr
cf.br ^bb36
^bb38:
%174 = arith.constant 1 : i1
func.return %174 : i1
}
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
func.func private @memset(!llvm.ptr, i64, i64) -> !llvm.ptr
// Constant: MOD
llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
// Constant: KMAX
llvm.mlir.global internal constant @KMAX(50 : i64) : i64
// Constant: N_TARGET
llvm.mlir.global internal constant @N_TARGET(1000000000000 : i64) : i64
// Constant: MAX_PRECOMP
llvm.mlir.global internal constant @MAX_PRECOMP(1000000 : i64) : i64
// Constant: STRIDE
llvm.mlir.global internal constant @STRIDE(0 : i64) : i64
// Module static: g_n
llvm.mlir.global internal @g_n(0 : i64) : i64
// Module static: g_m
llvm.mlir.global internal @g_m(0 : i64) : i64
// Module static: g_primes
llvm.mlir.global internal @g_primes() {addr_space = 0 : i32} : !llvm.ptr {
%175 = llvm.mlir.zero : !llvm.ptr
llvm.return %175 : !llvm.ptr
}
// Module static: g_p2
llvm.mlir.global internal @g_p2() {addr_space = 0 : i32} : !llvm.ptr {
%176 = llvm.mlir.zero : !llvm.ptr
llvm.return %176 : !llvm.ptr
}
// Module static: g_c
llvm.mlir.global internal @g_c() {addr_space = 0 : i32} : !llvm.ptr {
%177 = llvm.mlir.zero : !llvm.ptr
llvm.return %177 : !llvm.ptr
}
// Module static: g_ans_k
llvm.mlir.global internal @g_ans_k(0 : i64) : i64
// Module static: g_ps32
llvm.mlir.global internal @g_ps32() {addr_space = 0 : i32} : !llvm.ptr {
%178 = llvm.mlir.zero : !llvm.ptr
llvm.return %178 : !llvm.ptr
}
// Module static: g_coeff
llvm.mlir.global internal @g_coeff() {addr_space = 0 : i32} : !llvm.ptr {
%179 = llvm.mlir.zero : !llvm.ptr
llvm.return %179 : !llvm.ptr
}
// Module static: g_cache_keys
llvm.mlir.global internal @g_cache_keys() {addr_space = 0 : i32} : !llvm.ptr {
%180 = llvm.mlir.zero : !llvm.ptr
llvm.return %180 : !llvm.ptr
}
// Module static: g_cache_vals
llvm.mlir.global internal @g_cache_vals() {addr_space = 0 : i32} : !llvm.ptr {
%181 = llvm.mlir.zero : !llvm.ptr
llvm.return %181 : !llvm.ptr
}
// Module static: g_cache_count
llvm.mlir.global internal @g_cache_count(0 : i64) : i64
func.func @power_sum_large(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr) -> i64 {
%182 = llvm.mlir.addressof @MOD : !llvm.ptr
%183 = llvm.load %182 : !llvm.ptr -> i64
%184 = arith.remsi %arg0, %183 : i64
%185 = arith.constant 1 : i32
%187 = arith.extsi %185 : i32 to i64
%186 = arith.addi %184, %187 : i64
%188 = llvm.mlir.addressof @MOD : !llvm.ptr
%189 = llvm.load %188 : !llvm.ptr -> i64
%190 = arith.remsi %186, %189 : i64
%191 = llvm.mlir.constant(1 : i64) : i64
%192 = llvm.alloca %191 x i64 : (i64) -> !llvm.ptr
llvm.store %190, %192 : i64, !llvm.ptr
%193 = arith.constant 0 : i32
%194 = arith.extsi %193 : i32 to i64
%195 = llvm.mlir.constant(1 : i64) : i64
%196 = llvm.alloca %195 x i64 : (i64) -> !llvm.ptr
llvm.store %194, %196 : i64, !llvm.ptr
%197 = arith.constant 1 : i32
%198 = arith.constant 1 : i32
%200 = arith.extsi %198 : i32 to i64
%199 = arith.addi %arg1, %200 : i64
%201 = arith.index_cast %197 : i32 to index
%202 = arith.index_cast %199 : i32 to index
%204 = arith.constant 1 : index
%205 = arith.constant -1 : index
%206 = arith.cmpi sle, %201, %202 : index
%203 = arith.select %206, %204, %205 : index
cf.br ^bb42(%201 : index)
^bb42(%207: index):
%208 = arith.cmpi slt, %207, %202 : index
%209 = arith.cmpi sgt, %207, %202 : index
%210 = arith.select %206, %208, %209 : i1
cf.cond_br %210, ^bb43(%207 : index), ^bb44(%207 : index)
^bb43(%211: index):
%212 = arith.constant 1 : i32
%214 = arith.extsi %212 : i32 to i64
%213 = arith.addi %184, %214 : i64
%216 = arith.trunci %213 : i64 to i32
%217 = arith.index_cast %211 : index to i32
%215 = arith.subi %216, %217 : i32
%218 = llvm.mlir.addressof @MOD : !llvm.ptr
%219 = llvm.load %218 : !llvm.ptr -> i64
%221 = arith.extsi %215 : i32 to i64
%220 = arith.remsi %221, %219 : i64
%222 = arith.constant 0 : i32
%224 = arith.extsi %222 : i32 to i64
%223 = arith.cmpi slt, %220, %224 : i64
%225 = scf.if %223 -> (i64) {
%226 = llvm.mlir.addressof @MOD : !llvm.ptr
%227 = llvm.load %226 : !llvm.ptr -> i64
%228 = arith.addi %220, %227 : i64
scf.yield %228 : i64
} else {
scf.yield %220 : i64
}
%229 = llvm.load %192 : !llvm.ptr -> i64
%230 = arith.muli %229, %225 : i64
%231 = llvm.mlir.addressof @MOD : !llvm.ptr
%232 = llvm.load %231 : !llvm.ptr -> i64
%233 = arith.remsi %230, %232 : i64
llvm.store %233, %192 : i64, !llvm.ptr
%234 = llvm.load %196 : !llvm.ptr -> i64
%236 = arith.index_cast %211 : index to i64
%237 = llvm.getelementptr %arg2[%236] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%235 = llvm.load %237 : !llvm.ptr -> i64
%238 = llvm.load %192 : !llvm.ptr -> i64
%239 = arith.muli %235, %238 : i64
%240 = arith.addi %234, %239 : i64
%241 = llvm.mlir.addressof @MOD : !llvm.ptr
%242 = llvm.load %241 : !llvm.ptr -> i64
%243 = arith.remsi %240, %242 : i64
llvm.store %243, %196 : i64, !llvm.ptr
%244 = arith.addi %211, %203 : index
cf.br ^bb42(%244 : index)
^bb44(%245: index):
%246 = llvm.load %196 : !llvm.ptr -> i64
func.return %246 : i64
}
func.func @powsum(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: !llvm.ptr) -> i64 {
%247 = llvm.mlir.addressof @MAX_PRECOMP : !llvm.ptr
%248 = llvm.load %247 : !llvm.ptr -> i64
%249 = arith.cmpi sle, %arg0, %248 : i64
cf.cond_br %249, ^bb45, ^bb46
^bb45:
%251 = llvm.mlir.addressof @g_ps32 : !llvm.ptr
%252 = llvm.load %251 : !llvm.ptr -> !llvm.ptr
%253 = arith.addi %arg2, %arg0 : i64
%254 = llvm.getelementptr %252[%253] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%250 = llvm.load %254 : !llvm.ptr -> i32
%255 = arith.extsi %250 : i32 to i64
func.return %255 : i64
^bb46:
cf.br ^bb47
^bb47:
%256 = arith.constant 2000003 : i32
%258 = arith.extsi %256 : i32 to i64
%257 = arith.remsi %arg0, %258 : i64
%260 = llvm.mlir.addressof @g_cache_keys : !llvm.ptr
%261 = llvm.load %260 : !llvm.ptr -> !llvm.ptr
%262 = llvm.getelementptr %261[%257] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%259 = llvm.load %262 : !llvm.ptr -> i64
%263 = arith.cmpi eq, %259, %arg0 : i64
cf.cond_br %263, ^bb48, ^bb49
^bb48:
%265 = llvm.mlir.addressof @g_cache_vals : !llvm.ptr
%266 = llvm.load %265 : !llvm.ptr -> !llvm.ptr
%267 = llvm.getelementptr %266[%257] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%264 = llvm.load %267 : !llvm.ptr -> i64
func.return %264 : i64
^bb49:
cf.br ^bb50
^bb50:
%268 = func.call @power_sum_large(%arg0, %arg1, %arg3) : (i64, i64, !llvm.ptr) -> i64
%269 = llvm.mlir.addressof @g_cache_keys : !llvm.ptr
%270 = llvm.load %269 : !llvm.ptr -> !llvm.ptr
%271 = llvm.getelementptr %270[%257] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg0, %271 : i64, !llvm.ptr
%272 = llvm.mlir.addressof @g_cache_vals : !llvm.ptr
%273 = llvm.load %272 : !llvm.ptr -> !llvm.ptr
%274 = llvm.getelementptr %273[%257] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %268, %274 : i64, !llvm.ptr
func.return %268 : i64
}
func.func @dfs(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: i64, %arg5: !llvm.ptr) -> () {
%275 = llvm.mlir.addressof @g_ans_k : !llvm.ptr
%276 = llvm.load %275 : !llvm.ptr -> i64
%278 = llvm.mlir.addressof @g_n : !llvm.ptr
%279 = llvm.load %278 : !llvm.ptr -> i64
%280 = arith.divsi %279, %arg1 : i64
%277 = func.call @powsum(%280, %arg3, %arg4, %arg5) : (i64, i64, i64, !llvm.ptr) -> i64
%281 = arith.muli %277, %arg2 : i64
%282 = arith.addi %276, %281 : i64
%283 = llvm.mlir.addressof @MOD : !llvm.ptr
%284 = llvm.load %283 : !llvm.ptr -> i64
%285 = arith.remsi %282, %284 : i64
%286 = llvm.mlir.addressof @g_ans_k : !llvm.ptr
llvm.store %285, %286 : i64, !llvm.ptr
%287 = llvm.mlir.addressof @g_n : !llvm.ptr
%288 = llvm.load %287 : !llvm.ptr -> i64
%289 = arith.divsi %288, %arg1 : i64
%290 = llvm.mlir.constant(1 : i64) : i64
%291 = llvm.alloca %290 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %291 : i64, !llvm.ptr
%292 = llvm.mlir.addressof @g_m : !llvm.ptr
%293 = llvm.load %292 : !llvm.ptr -> i64
%294 = llvm.mlir.constant(1 : i64) : i64
%295 = llvm.alloca %294 x i64 : (i64) -> !llvm.ptr
llvm.store %293, %295 : i64, !llvm.ptr
cf.br ^bb51
^bb51:
%296 = llvm.load %291 : !llvm.ptr -> i64
%297 = llvm.load %295 : !llvm.ptr -> i64
%298 = arith.cmpi slt, %296, %297 : i64
cf.cond_br %298, ^bb52, ^bb53
^bb52:
%299 = llvm.load %291 : !llvm.ptr -> i64
%300 = llvm.load %295 : !llvm.ptr -> i64
%301 = arith.addi %299, %300 : i64
%302 = arith.constant 2 : i32
%304 = arith.extsi %302 : i32 to i64
%303 = arith.divsi %301, %304 : i64
%306 = llvm.mlir.addressof @g_p2 : !llvm.ptr
%307 = llvm.load %306 : !llvm.ptr -> !llvm.ptr
%308 = llvm.getelementptr %307[%303] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%305 = llvm.load %308 : !llvm.ptr -> i64
%309 = arith.cmpi sle, %305, %289 : i64
cf.cond_br %309, ^bb54, ^bb55
^bb54:
%310 = arith.constant 1 : i32
%312 = arith.extsi %310 : i32 to i64
%311 = arith.addi %303, %312 : i64
llvm.store %311, %291 : i64, !llvm.ptr
cf.br ^bb56
^bb55:
llvm.store %303, %295 : i64, !llvm.ptr
cf.br ^bb56
^bb56:
cf.br ^bb51
^bb53:
%313 = llvm.load %291 : !llvm.ptr -> i64
%314 = arith.index_cast %arg0 : i32 to index
%315 = arith.index_cast %313 : i32 to index
%317 = arith.constant 1 : index
%318 = arith.constant -1 : index
%319 = arith.cmpi sle, %314, %315 : index
%316 = arith.select %319, %317, %318 : index
cf.br ^bb57(%314 : index)
^bb57(%320: index):
%321 = arith.cmpi slt, %320, %315 : index
%322 = arith.cmpi sgt, %320, %315 : index
%323 = arith.select %319, %321, %322 : i1
cf.cond_br %323, ^bb58(%320 : index), ^bb59(%320 : index)
^bb58(%324: index):
%326 = llvm.mlir.addressof @g_p2 : !llvm.ptr
%327 = llvm.load %326 : !llvm.ptr -> !llvm.ptr
%328 = arith.index_cast %324 : index to i64
%329 = llvm.getelementptr %327[%328] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%325 = llvm.load %329 : !llvm.ptr -> i64
%330 = arith.muli %arg1, %325 : i64
%332 = llvm.mlir.addressof @g_c : !llvm.ptr
%333 = llvm.load %332 : !llvm.ptr -> !llvm.ptr
%334 = arith.index_cast %324 : index to i64
%335 = llvm.getelementptr %333[%334] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%331 = llvm.load %335 : !llvm.ptr -> i64
%336 = arith.muli %arg2, %331 : i64
%337 = llvm.mlir.addressof @MOD : !llvm.ptr
%338 = llvm.load %337 : !llvm.ptr -> i64
%339 = arith.remsi %336, %338 : i64
%341 = llvm.mlir.addressof @g_primes : !llvm.ptr
%342 = llvm.load %341 : !llvm.ptr -> !llvm.ptr
%343 = arith.index_cast %324 : index to i64
%344 = llvm.getelementptr %342[%343] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%340 = llvm.load %344 : !llvm.ptr -> i64
%345 = llvm.mlir.constant(1 : i64) : i64
%346 = llvm.alloca %345 x i64 : (i64) -> !llvm.ptr
llvm.store %330, %346 : i64, !llvm.ptr
cf.br ^bb60
^bb60:
%347 = llvm.load %346 : !llvm.ptr -> i64
%348 = llvm.mlir.addressof @g_n : !llvm.ptr
%349 = llvm.load %348 : !llvm.ptr -> i64
%350 = arith.cmpi sle, %347, %349 : i64
cf.cond_br %350, ^bb61, ^bb62
^bb61:
%352 = arith.constant 1 : i32
%354 = arith.index_cast %324 : index to i32
%353 = arith.addi %354, %352 : i32
%355 = llvm.load %346 : !llvm.ptr -> i64
%356 = arith.extsi %353 : i32 to i64
func.call @dfs(%356, %355, %339, %arg3, %arg4, %arg5) : (i64, i64, i64, i64, i64, !llvm.ptr) -> ()
%357 = llvm.load %346 : !llvm.ptr -> i64
%358 = llvm.mlir.addressof @g_n : !llvm.ptr
%359 = llvm.load %358 : !llvm.ptr -> i64
%360 = arith.divsi %359, %340 : i64
%361 = arith.cmpi sgt, %357, %360 : i64
cf.cond_br %361, ^bb63, ^bb64
^bb63:
cf.br ^bb62
^bb64:
cf.br ^bb65
^bb65:
%362 = llvm.load %346 : !llvm.ptr -> i64
%363 = arith.muli %362, %340 : i64
llvm.store %363, %346 : i64, !llvm.ptr
cf.br ^bb60
^bb62:
%364 = arith.addi %324, %316 : index
cf.br ^bb57(%364 : index)
^bb59(%365: index):
func.return
}
func.func @main() -> i32 {
%367 = llvm.mlir.addressof @N_TARGET : !llvm.ptr
%368 = llvm.load %367 : !llvm.ptr -> i64
%366 = func.call @isqrt(%368) : (i64) -> i64
%370 = arith.constant 1 : i32
%372 = arith.extsi %370 : i32 to i64
%371 = arith.addi %366, %372 : i64
%373 = arith.constant 8 : i32
%374 = arith.extsi %373 : i32 to i64
%369 = func.call @calloc(%371, %374) : (i64, i64) -> !llvm.ptr
%376 = arith.constant 10 : i32
%378 = arith.extsi %376 : i32 to i64
%377 = arith.divsi %366, %378 : i64
%379 = arith.constant 100 : i32
%381 = arith.extsi %379 : i32 to i64
%380 = arith.addi %377, %381 : i64
%382 = arith.constant 8 : i32
%383 = arith.extsi %382 : i32 to i64
%375 = func.call @calloc(%380, %383) : (i64, i64) -> !llvm.ptr
%384 = arith.constant 0 : i32
%385 = arith.extsi %384 : i32 to i64
%386 = llvm.mlir.constant(1 : i64) : i64
%387 = llvm.alloca %386 x i64 : (i64) -> !llvm.ptr
llvm.store %385, %387 : i64, !llvm.ptr
%388 = arith.constant 2 : i32
%389 = arith.constant 1 : i32
%391 = arith.extsi %389 : i32 to i64
%390 = arith.addi %366, %391 : i64
%392 = arith.index_cast %388 : i32 to index
%393 = arith.index_cast %390 : i32 to index
%395 = arith.constant 1 : index
%396 = arith.constant -1 : index
%397 = arith.cmpi sle, %392, %393 : index
%394 = arith.select %397, %395, %396 : index
cf.br ^bb66(%392 : index)
^bb66(%398: index):
%399 = arith.cmpi slt, %398, %393 : index
%400 = arith.cmpi sgt, %398, %393 : index
%401 = arith.select %397, %399, %400 : i1
cf.cond_br %401, ^bb67(%398 : index), ^bb68(%398 : index)
^bb67(%402: index):
%404 = arith.index_cast %402 : index to i64
%405 = llvm.getelementptr %369[%404] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%403 = llvm.load %405 : !llvm.ptr -> i64
%406 = arith.constant 0 : i32
%408 = arith.extsi %406 : i32 to i64
%407 = arith.cmpi eq, %403, %408 : i64
cf.cond_br %407, ^bb69, ^bb70
^bb69:
%409 = llvm.load %387 : !llvm.ptr -> i64
%410 = arith.index_cast %402 : index to i64
%411 = llvm.getelementptr %375[%409] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %410, %411 : i64, !llvm.ptr
%412 = llvm.load %387 : !llvm.ptr -> i64
%413 = arith.constant 1 : i32
%415 = arith.extsi %413 : i32 to i64
%414 = arith.addi %412, %415 : i64
llvm.store %414, %387 : i64, !llvm.ptr
%416 = arith.index_cast %402 : index to i64
%417 = arith.index_cast %402 : index to i64
%418 = arith.muli %416, %417 : i64
%419 = llvm.mlir.constant(1 : i64) : i64
%420 = llvm.alloca %419 x i64 : (i64) -> !llvm.ptr
llvm.store %418, %420 : i64, !llvm.ptr
cf.br ^bb72
^bb72:
%421 = llvm.load %420 : !llvm.ptr -> i64
%422 = arith.cmpi sle, %421, %366 : i64
cf.cond_br %422, ^bb73, ^bb74
^bb73:
%423 = arith.constant 1 : i32
%424 = llvm.load %420 : !llvm.ptr -> i64
%425 = arith.extsi %423 : i32 to i64
%426 = llvm.getelementptr %369[%424] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %425, %426 : i64, !llvm.ptr
%427 = llvm.load %420 : !llvm.ptr -> i64
%429 = arith.trunci %427 : i64 to i32
%430 = arith.index_cast %402 : index to i32
%428 = arith.addi %429, %430 : i32
%431 = arith.extsi %428 : i32 to i64
llvm.store %431, %420 : i64, !llvm.ptr
cf.br ^bb72
^bb74:
cf.br ^bb71
^bb70:
cf.br ^bb71
^bb71:
%432 = arith.addi %402, %394 : index
cf.br ^bb66(%432 : index)
^bb68(%433: index):
func.call @free(%369) : (!llvm.ptr) -> ()
%436 = llvm.load %387 : !llvm.ptr -> i64
%437 = arith.constant 8 : i32
%438 = arith.extsi %437 : i32 to i64
%435 = func.call @calloc(%436, %438) : (i64, i64) -> !llvm.ptr
%439 = arith.constant 0 : i32
%440 = llvm.load %387 : !llvm.ptr -> i64
%441 = arith.index_cast %439 : i32 to index
%442 = arith.index_cast %440 : i32 to index
%444 = arith.constant 1 : index
%445 = arith.constant -1 : index
%446 = arith.cmpi sle, %441, %442 : index
%443 = arith.select %446, %444, %445 : index
cf.br ^bb75(%441 : index)
^bb75(%447: index):
%448 = arith.cmpi slt, %447, %442 : index
%449 = arith.cmpi sgt, %447, %442 : index
%450 = arith.select %446, %448, %449 : i1
cf.cond_br %450, ^bb76(%447 : index), ^bb77(%447 : index)
^bb76(%451: index):
%453 = arith.index_cast %451 : index to i64
%454 = llvm.getelementptr %375[%453] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%452 = llvm.load %454 : !llvm.ptr -> i64
%456 = arith.index_cast %451 : index to i64
%457 = llvm.getelementptr %375[%456] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%455 = llvm.load %457 : !llvm.ptr -> i64
%458 = arith.muli %452, %455 : i64
%459 = arith.index_cast %451 : index to i64
%460 = llvm.getelementptr %435[%459] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %458, %460 : i64, !llvm.ptr
%461 = arith.addi %451, %443 : index
cf.br ^bb75(%461 : index)
^bb77(%462: index):
%464 = llvm.mlir.addressof @KMAX : !llvm.ptr
%465 = llvm.load %464 : !llvm.ptr -> i64
%466 = arith.constant 1 : i32
%468 = arith.extsi %466 : i32 to i64
%467 = arith.addi %465, %468 : i64
%469 = llvm.mlir.addressof @KMAX : !llvm.ptr
%470 = llvm.load %469 : !llvm.ptr -> i64
%471 = arith.constant 1 : i32
%473 = arith.extsi %471 : i32 to i64
%472 = arith.addi %470, %473 : i64
%474 = arith.muli %467, %472 : i64
%475 = arith.constant 8 : i32
%476 = arith.extsi %475 : i32 to i64
%463 = func.call @calloc(%474, %476) : (i64, i64) -> !llvm.ptr
%477 = arith.constant 1 : i32
%478 = arith.constant 0 : i32
%479 = arith.extsi %477 : i32 to i64
%480 = arith.extsi %478 : i32 to i64
%481 = llvm.getelementptr %463[%480] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %479, %481 : i64, !llvm.ptr
%482 = arith.constant 1 : i32
%483 = llvm.mlir.addressof @KMAX : !llvm.ptr
%484 = llvm.load %483 : !llvm.ptr -> i64
%485 = arith.constant 1 : i32
%487 = arith.extsi %485 : i32 to i64
%486 = arith.addi %484, %487 : i64
%488 = arith.index_cast %482 : i32 to index
%489 = arith.index_cast %486 : i32 to index
%491 = arith.constant 1 : index
%492 = arith.constant -1 : index
%493 = arith.cmpi sle, %488, %489 : index
%490 = arith.select %493, %491, %492 : index
cf.br ^bb78(%488 : index)
^bb78(%494: index):
%495 = arith.cmpi slt, %494, %489 : index
%496 = arith.cmpi sgt, %494, %489 : index
%497 = arith.select %493, %495, %496 : i1
cf.cond_br %497, ^bb79(%494 : index), ^bb80(%494 : index)
^bb79(%498: index):
%499 = arith.constant 1 : i32
%500 = arith.constant 1 : i32
%502 = arith.index_cast %498 : index to i32
%501 = arith.addi %502, %500 : i32
%503 = arith.index_cast %499 : i32 to index
%504 = arith.index_cast %501 : i32 to index
%506 = arith.constant 1 : index
%507 = arith.constant -1 : index
%508 = arith.cmpi sle, %503, %504 : index
%505 = arith.select %508, %506, %507 : index
cf.br ^bb81(%503 : index)
^bb81(%509: index):
%510 = arith.cmpi slt, %509, %504 : index
%511 = arith.cmpi sgt, %509, %504 : index
%512 = arith.select %508, %510, %511 : i1
cf.cond_br %512, ^bb82(%509 : index), ^bb83(%509 : index)
^bb82(%513: index):
%515 = arith.constant 1 : i32
%517 = arith.index_cast %498 : index to i32
%516 = arith.subi %517, %515 : i32
%518 = llvm.mlir.addressof @KMAX : !llvm.ptr
%519 = llvm.load %518 : !llvm.ptr -> i64
%520 = arith.constant 1 : i32
%522 = arith.extsi %520 : i32 to i64
%521 = arith.addi %519, %522 : i64
%524 = arith.extsi %516 : i32 to i64
%523 = arith.muli %524, %521 : i64
%526 = arith.trunci %523 : i64 to i32
%527 = arith.index_cast %513 : index to i32
%525 = arith.addi %526, %527 : i32
%528 = arith.constant 1 : i32
%529 = arith.subi %525, %528 : i32
%530 = arith.extsi %529 : i32 to i64
%531 = llvm.getelementptr %463[%530] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%514 = llvm.load %531 : !llvm.ptr -> i64
%533 = arith.constant 1 : i32
%535 = arith.index_cast %498 : index to i32
%534 = arith.subi %535, %533 : i32
%536 = llvm.mlir.addressof @KMAX : !llvm.ptr
%537 = llvm.load %536 : !llvm.ptr -> i64
%538 = arith.constant 1 : i32
%540 = arith.extsi %538 : i32 to i64
%539 = arith.addi %537, %540 : i64
%542 = arith.extsi %534 : i32 to i64
%541 = arith.muli %542, %539 : i64
%544 = arith.trunci %541 : i64 to i32
%545 = arith.index_cast %513 : index to i32
%543 = arith.addi %544, %545 : i32
%546 = arith.extsi %543 : i32 to i64
%547 = llvm.getelementptr %463[%546] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%532 = llvm.load %547 : !llvm.ptr -> i64
%549 = arith.index_cast %513 : index to i32
%550 = arith.trunci %532 : i64 to i32
%548 = arith.muli %549, %550 : i32
%552 = arith.extsi %548 : i32 to i64
%551 = arith.addi %514, %552 : i64
%553 = llvm.mlir.addressof @MOD : !llvm.ptr
%554 = llvm.load %553 : !llvm.ptr -> i64
%555 = arith.remsi %551, %554 : i64
%556 = llvm.mlir.addressof @KMAX : !llvm.ptr
%557 = llvm.load %556 : !llvm.ptr -> i64
%558 = arith.constant 1 : i32
%560 = arith.extsi %558 : i32 to i64
%559 = arith.addi %557, %560 : i64
%562 = arith.index_cast %498 : index to i32
%563 = arith.trunci %559 : i64 to i32
%561 = arith.muli %562, %563 : i32
%565 = arith.index_cast %513 : index to i32
%564 = arith.addi %561, %565 : i32
%566 = arith.extsi %564 : i32 to i64
%567 = llvm.getelementptr %463[%566] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %555, %567 : i64, !llvm.ptr
%568 = arith.addi %513, %505 : index
cf.br ^bb81(%568 : index)
^bb83(%569: index):
%570 = arith.addi %498, %490 : index
cf.br ^bb78(%570 : index)
^bb80(%571: index):
%573 = llvm.mlir.addressof @KMAX : !llvm.ptr
%574 = llvm.load %573 : !llvm.ptr -> i64
%575 = arith.constant 2 : i32
%577 = arith.extsi %575 : i32 to i64
%576 = arith.addi %574, %577 : i64
%578 = arith.constant 8 : i32
%579 = arith.extsi %578 : i32 to i64
%572 = func.call @calloc(%576, %579) : (i64, i64) -> !llvm.ptr
%580 = arith.constant 1 : i32
%581 = arith.constant 1 : i32
%582 = arith.extsi %580 : i32 to i64
%583 = arith.extsi %581 : i32 to i64
%584 = llvm.getelementptr %572[%583] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %582, %584 : i64, !llvm.ptr
%585 = arith.constant 2 : i32
%586 = llvm.mlir.addressof @KMAX : !llvm.ptr
%587 = llvm.load %586 : !llvm.ptr -> i64
%588 = arith.constant 2 : i32
%590 = arith.extsi %588 : i32 to i64
%589 = arith.addi %587, %590 : i64
%591 = arith.index_cast %585 : i32 to index
%592 = arith.index_cast %589 : i32 to index
%594 = arith.constant 1 : index
%595 = arith.constant -1 : index
%596 = arith.cmpi sle, %591, %592 : index
%593 = arith.select %596, %594, %595 : index
cf.br ^bb84(%591 : index)
^bb84(%597: index):
%598 = arith.cmpi slt, %597, %592 : index
%599 = arith.cmpi sgt, %597, %592 : index
%600 = arith.select %596, %598, %599 : i1
cf.cond_br %600, ^bb85(%597 : index), ^bb86(%597 : index)
^bb85(%601: index):
%602 = llvm.mlir.addressof @MOD : !llvm.ptr
%603 = llvm.load %602 : !llvm.ptr -> i64
%604 = llvm.mlir.addressof @MOD : !llvm.ptr
%605 = llvm.load %604 : !llvm.ptr -> i64
%607 = arith.trunci %605 : i64 to i32
%608 = arith.index_cast %601 : index to i32
%606 = arith.divsi %607, %608 : i32
%610 = arith.extsi %606 : i32 to i64
%609 = arith.subi %603, %610 : i64
%612 = llvm.mlir.addressof @MOD : !llvm.ptr
%613 = llvm.load %612 : !llvm.ptr -> i64
%615 = arith.trunci %613 : i64 to i32
%616 = arith.index_cast %601 : index to i32
%614 = arith.remsi %615, %616 : i32
%617 = arith.extsi %614 : i32 to i64
%618 = llvm.getelementptr %572[%617] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%611 = llvm.load %618 : !llvm.ptr -> i64
%619 = arith.muli %609, %611 : i64
%620 = llvm.mlir.addressof @MOD : !llvm.ptr
%621 = llvm.load %620 : !llvm.ptr -> i64
%622 = arith.remsi %619, %621 : i64
%623 = arith.index_cast %601 : index to i64
%624 = llvm.getelementptr %572[%623] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %622, %624 : i64, !llvm.ptr
%625 = arith.addi %601, %593 : index
cf.br ^bb84(%625 : index)
^bb86(%626: index):
%628 = llvm.mlir.addressof @KMAX : !llvm.ptr
%629 = llvm.load %628 : !llvm.ptr -> i64
%630 = arith.constant 1 : i32
%632 = arith.extsi %630 : i32 to i64
%631 = arith.addi %629, %632 : i64
%633 = llvm.mlir.addressof @KMAX : !llvm.ptr
%634 = llvm.load %633 : !llvm.ptr -> i64
%635 = arith.constant 1 : i32
%637 = arith.extsi %635 : i32 to i64
%636 = arith.addi %634, %637 : i64
%638 = arith.muli %631, %636 : i64
%639 = arith.constant 8 : i32
%640 = arith.extsi %639 : i32 to i64
%627 = func.call @calloc(%638, %640) : (i64, i64) -> !llvm.ptr
%641 = arith.constant 1 : i32
%642 = llvm.mlir.addressof @KMAX : !llvm.ptr
%643 = llvm.load %642 : !llvm.ptr -> i64
%644 = arith.constant 1 : i32
%646 = arith.extsi %644 : i32 to i64
%645 = arith.addi %643, %646 : i64
%647 = arith.index_cast %641 : i32 to index
%648 = arith.index_cast %645 : i32 to index
%650 = arith.constant 1 : index
%651 = arith.constant -1 : index
%652 = arith.cmpi sle, %647, %648 : index
%649 = arith.select %652, %650, %651 : index
cf.br ^bb87(%647 : index)
^bb87(%653: index):
%654 = arith.cmpi slt, %653, %648 : index
%655 = arith.cmpi sgt, %653, %648 : index
%656 = arith.select %652, %654, %655 : i1
cf.cond_br %656, ^bb88(%653 : index), ^bb89(%653 : index)
^bb88(%657: index):
%658 = arith.constant 1 : i32
%659 = arith.constant 1 : i32
%661 = arith.index_cast %657 : index to i32
%660 = arith.addi %661, %659 : i32
%662 = arith.index_cast %658 : i32 to index
%663 = arith.index_cast %660 : i32 to index
%665 = arith.constant 1 : index
%666 = arith.constant -1 : index
%667 = arith.cmpi sle, %662, %663 : index
%664 = arith.select %667, %665, %666 : index
cf.br ^bb90(%662 : index)
^bb90(%668: index):
%669 = arith.cmpi slt, %668, %663 : index
%670 = arith.cmpi sgt, %668, %663 : index
%671 = arith.select %667, %669, %670 : i1
cf.cond_br %671, ^bb91(%668 : index), ^bb92(%668 : index)
^bb91(%672: index):
%674 = llvm.mlir.addressof @KMAX : !llvm.ptr
%675 = llvm.load %674 : !llvm.ptr -> i64
%676 = arith.constant 1 : i32
%678 = arith.extsi %676 : i32 to i64
%677 = arith.addi %675, %678 : i64
%680 = arith.index_cast %657 : index to i32
%681 = arith.trunci %677 : i64 to i32
%679 = arith.muli %680, %681 : i32
%683 = arith.index_cast %672 : index to i32
%682 = arith.addi %679, %683 : i32
%684 = arith.extsi %682 : i32 to i64
%685 = llvm.getelementptr %463[%684] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%673 = llvm.load %685 : !llvm.ptr -> i64
%687 = arith.constant 1 : i32
%689 = arith.index_cast %672 : index to i32
%688 = arith.addi %689, %687 : i32
%690 = arith.extsi %688 : i32 to i64
%691 = llvm.getelementptr %572[%690] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%686 = llvm.load %691 : !llvm.ptr -> i64
%692 = arith.muli %673, %686 : i64
%693 = llvm.mlir.addressof @MOD : !llvm.ptr
%694 = llvm.load %693 : !llvm.ptr -> i64
%695 = arith.remsi %692, %694 : i64
%696 = llvm.mlir.addressof @KMAX : !llvm.ptr
%697 = llvm.load %696 : !llvm.ptr -> i64
%698 = arith.constant 1 : i32
%700 = arith.extsi %698 : i32 to i64
%699 = arith.addi %697, %700 : i64
%702 = arith.index_cast %657 : index to i32
%703 = arith.trunci %699 : i64 to i32
%701 = arith.muli %702, %703 : i32
%705 = arith.index_cast %672 : index to i32
%704 = arith.addi %701, %705 : i32
%706 = arith.extsi %704 : i32 to i64
%707 = llvm.getelementptr %627[%706] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %695, %707 : i64, !llvm.ptr
%708 = arith.addi %672, %664 : index
cf.br ^bb90(%708 : index)
^bb92(%709: index):
%710 = arith.addi %657, %649 : index
cf.br ^bb87(%710 : index)
^bb89(%711: index):
func.call @free(%463) : (!llvm.ptr) -> ()
%713 = llvm.mlir.addressof @KMAX : !llvm.ptr
%714 = llvm.load %713 : !llvm.ptr -> i64
%715 = arith.constant 1 : i32
%717 = arith.extsi %715 : i32 to i64
%716 = arith.addi %714, %717 : i64
%718 = llvm.mlir.addressof @STRIDE : !llvm.ptr
%719 = llvm.load %718 : !llvm.ptr -> i64
%720 = arith.muli %716, %719 : i64
%722 = arith.constant 4 : i32
%723 = arith.extsi %722 : i32 to i64
%721 = func.call @calloc(%720, %723) : (i64, i64) -> !llvm.ptr
%724 = llvm.mlir.zero : !llvm.ptr
%725 = llvm.icmp "eq" %721, %724 : !llvm.ptr
cf.cond_br %725, ^bb93, ^bb94
^bb93:
%726 = llvm.mlir.addressof @str_0 : !llvm.ptr
%727 = llvm.call @printf(%726) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr) -> i32
%728 = arith.constant 1 : i32
func.return %728 : i32
^bb94:
cf.br ^bb95
^bb95:
%729 = llvm.mlir.addressof @g_ps32 : !llvm.ptr
llvm.store %721, %729 : !llvm.ptr, !llvm.ptr
%730 = arith.constant 1 : i32
%731 = llvm.mlir.addressof @STRIDE : !llvm.ptr
%732 = llvm.load %731 : !llvm.ptr -> i64
%733 = arith.index_cast %730 : i32 to index
%734 = arith.index_cast %732 : i32 to index
%736 = arith.constant 1 : index
%737 = arith.constant -1 : index
%738 = arith.cmpi sle, %733, %734 : index
%735 = arith.select %738, %736, %737 : index
cf.br ^bb96(%733 : index)
^bb96(%739: index):
%740 = arith.cmpi slt, %739, %734 : index
%741 = arith.cmpi sgt, %739, %734 : index
%742 = arith.select %738, %740, %741 : i1
cf.cond_br %742, ^bb97(%739 : index), ^bb98(%739 : index)
^bb97(%743: index):
%744 = arith.index_cast %743 : index to i64
%745 = llvm.mlir.constant(1 : i64) : i64
%746 = llvm.alloca %745 x i64 : (i64) -> !llvm.ptr
llvm.store %744, %746 : i64, !llvm.ptr
%747 = arith.constant 1 : i32
%748 = llvm.mlir.addressof @KMAX : !llvm.ptr
%749 = llvm.load %748 : !llvm.ptr -> i64
%750 = arith.constant 1 : i32
%752 = arith.extsi %750 : i32 to i64
%751 = arith.addi %749, %752 : i64
%753 = arith.index_cast %747 : i32 to index
%754 = arith.index_cast %751 : i32 to index
%756 = arith.constant 1 : index
%757 = arith.constant -1 : index
%758 = arith.cmpi sle, %753, %754 : index
%755 = arith.select %758, %756, %757 : index
cf.br ^bb99(%753 : index)
^bb99(%759: index):
%760 = arith.cmpi slt, %759, %754 : index
%761 = arith.cmpi sgt, %759, %754 : index
%762 = arith.select %758, %760, %761 : i1
cf.cond_br %762, ^bb100(%759 : index), ^bb101(%759 : index)
^bb100(%763: index):
%764 = llvm.mlir.addressof @STRIDE : !llvm.ptr
%765 = llvm.load %764 : !llvm.ptr -> i64
%767 = arith.index_cast %763 : index to i32
%768 = arith.trunci %765 : i64 to i32
%766 = arith.muli %767, %768 : i32
%770 = arith.index_cast %743 : index to i32
%769 = arith.addi %766, %770 : i32
%771 = arith.extsi %769 : i32 to i64
%773 = arith.constant 1 : i32
%775 = arith.extsi %773 : i32 to i64
%774 = arith.subi %771, %775 : i64
%776 = llvm.getelementptr %721[%774] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%772 = llvm.load %776 : !llvm.ptr -> i32
%777 = arith.extsi %772 : i32 to i64
%778 = llvm.load %746 : !llvm.ptr -> i64
%779 = arith.addi %777, %778 : i64
%780 = llvm.mlir.addressof @MOD : !llvm.ptr
%781 = llvm.load %780 : !llvm.ptr -> i64
%782 = arith.remsi %779, %781 : i64
%783 = arith.trunci %782 : i64 to i32
%784 = llvm.getelementptr %721[%771] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %783, %784 : i32, !llvm.ptr
%785 = llvm.load %746 : !llvm.ptr -> i64
%786 = arith.muli %785, %744 : i64
%787 = llvm.mlir.addressof @MOD : !llvm.ptr
%788 = llvm.load %787 : !llvm.ptr -> i64
%789 = arith.remsi %786, %788 : i64
llvm.store %789, %746 : i64, !llvm.ptr
%790 = arith.addi %763, %755 : index
cf.br ^bb99(%790 : index)
^bb101(%791: index):
%792 = arith.addi %743, %735 : index
cf.br ^bb96(%792 : index)
^bb98(%793: index):
%794 = llvm.mlir.addressof @N_TARGET : !llvm.ptr
%795 = llvm.load %794 : !llvm.ptr -> i64
%796 = llvm.mlir.addressof @g_n : !llvm.ptr
llvm.store %795, %796 : i64, !llvm.ptr
%797 = llvm.load %387 : !llvm.ptr -> i64
%798 = llvm.mlir.addressof @g_m : !llvm.ptr
llvm.store %797, %798 : i64, !llvm.ptr
%799 = llvm.mlir.addressof @g_primes : !llvm.ptr
llvm.store %375, %799 : !llvm.ptr, !llvm.ptr
%800 = llvm.mlir.addressof @g_p2 : !llvm.ptr
llvm.store %435, %800 : !llvm.ptr, !llvm.ptr
%801 = arith.constant 2000003 : i32
%802 = arith.extsi %801 : i32 to i64
%804 = arith.constant 8 : i32
%805 = arith.extsi %804 : i32 to i64
%803 = func.call @calloc(%802, %805) : (i64, i64) -> !llvm.ptr
%806 = llvm.mlir.addressof @g_cache_keys : !llvm.ptr
llvm.store %803, %806 : !llvm.ptr, !llvm.ptr
%808 = arith.constant 8 : i32
%809 = arith.extsi %808 : i32 to i64
%807 = func.call @calloc(%802, %809) : (i64, i64) -> !llvm.ptr
%810 = llvm.mlir.addressof @g_cache_vals : !llvm.ptr
llvm.store %807, %810 : !llvm.ptr, !llvm.ptr
%811 = arith.constant 0 : i32
%812 = arith.extsi %811 : i32 to i64
%813 = llvm.mlir.addressof @g_cache_count : !llvm.ptr
llvm.store %812, %813 : i64, !llvm.ptr
%815 = llvm.load %387 : !llvm.ptr -> i64
%816 = arith.constant 8 : i32
%817 = arith.extsi %816 : i32 to i64
%814 = func.call @calloc(%815, %817) : (i64, i64) -> !llvm.ptr
%818 = llvm.mlir.addressof @g_c : !llvm.ptr
llvm.store %814, %818 : !llvm.ptr, !llvm.ptr
%820 = llvm.load %387 : !llvm.ptr -> i64
%821 = arith.constant 8 : i32
%822 = arith.extsi %821 : i32 to i64
%819 = func.call @calloc(%820, %822) : (i64, i64) -> !llvm.ptr
%823 = arith.constant 0 : i32
%824 = llvm.load %387 : !llvm.ptr -> i64
%825 = arith.index_cast %823 : i32 to index
%826 = arith.index_cast %824 : i32 to index
%828 = arith.constant 1 : index
%829 = arith.constant -1 : index
%830 = arith.cmpi sle, %825, %826 : index
%827 = arith.select %830, %828, %829 : index
cf.br ^bb102(%825 : index)
^bb102(%831: index):
%832 = arith.cmpi slt, %831, %826 : index
%833 = arith.cmpi sgt, %831, %826 : index
%834 = arith.select %830, %832, %833 : i1
cf.cond_br %834, ^bb103(%831 : index), ^bb104(%831 : index)
^bb103(%835: index):
%836 = arith.constant 1 : i32
%837 = arith.extsi %836 : i32 to i64
%838 = arith.index_cast %835 : index to i64
%839 = llvm.getelementptr %819[%838] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %837, %839 : i64, !llvm.ptr
%840 = arith.addi %835, %827 : index
cf.br ^bb102(%840 : index)
^bb104(%841: index):
%842 = arith.constant 0 : i32
%843 = arith.extsi %842 : i32 to i64
%844 = llvm.mlir.constant(1 : i64) : i64
%845 = llvm.alloca %844 x i64 : (i64) -> !llvm.ptr
llvm.store %843, %845 : i64, !llvm.ptr
%846 = arith.constant 1 : i32
%847 = llvm.mlir.addressof @KMAX : !llvm.ptr
%848 = llvm.load %847 : !llvm.ptr -> i64
%849 = arith.constant 1 : i32
%851 = arith.extsi %849 : i32 to i64
%850 = arith.addi %848, %851 : i64
%852 = arith.index_cast %846 : i32 to index
%853 = arith.index_cast %850 : i32 to index
%855 = arith.constant 1 : index
%856 = arith.constant -1 : index
%857 = arith.cmpi sle, %852, %853 : index
%854 = arith.select %857, %855, %856 : index
cf.br ^bb105(%852 : index)
^bb105(%858: index):
%859 = arith.cmpi slt, %858, %853 : index
%860 = arith.cmpi sgt, %858, %853 : index
%861 = arith.select %857, %859, %860 : i1
cf.cond_br %861, ^bb106(%858 : index), ^bb107(%858 : index)
^bb106(%862: index):
%863 = arith.constant 0 : i32
%864 = llvm.load %387 : !llvm.ptr -> i64
%865 = arith.index_cast %863 : i32 to index
%866 = arith.index_cast %864 : i32 to index
%868 = arith.constant 1 : index
%869 = arith.constant -1 : index
%870 = arith.cmpi sle, %865, %866 : index
%867 = arith.select %870, %868, %869 : index
cf.br ^bb108(%865 : index)
^bb108(%871: index):
%872 = arith.cmpi slt, %871, %866 : index
%873 = arith.cmpi sgt, %871, %866 : index
%874 = arith.select %870, %872, %873 : i1
cf.cond_br %874, ^bb109(%871 : index), ^bb110(%871 : index)
^bb109(%875: index):
%877 = arith.index_cast %875 : index to i64
%878 = llvm.getelementptr %819[%877] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%876 = llvm.load %878 : !llvm.ptr -> i64
%880 = arith.index_cast %875 : index to i64
%881 = llvm.getelementptr %375[%880] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%879 = llvm.load %881 : !llvm.ptr -> i64
%882 = arith.muli %876, %879 : i64
%883 = llvm.mlir.addressof @MOD : !llvm.ptr
%884 = llvm.load %883 : !llvm.ptr -> i64
%885 = arith.remsi %882, %884 : i64
%886 = arith.index_cast %875 : index to i64
%887 = llvm.getelementptr %819[%886] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %885, %887 : i64, !llvm.ptr
%888 = arith.muli %885, %885 : i64
%889 = llvm.mlir.addressof @MOD : !llvm.ptr
%890 = llvm.load %889 : !llvm.ptr -> i64
%891 = arith.remsi %888, %890 : i64
%892 = arith.subi %885, %891 : i64
%893 = llvm.mlir.addressof @MOD : !llvm.ptr
%894 = llvm.load %893 : !llvm.ptr -> i64
%895 = arith.remsi %892, %894 : i64
%896 = arith.index_cast %875 : index to i64
%897 = llvm.getelementptr %814[%896] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %895, %897 : i64, !llvm.ptr
%899 = arith.index_cast %875 : index to i64
%900 = llvm.getelementptr %814[%899] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%898 = llvm.load %900 : !llvm.ptr -> i64
%901 = arith.constant 0 : i32
%903 = arith.extsi %901 : i32 to i64
%902 = arith.cmpi slt, %898, %903 : i64
cf.cond_br %902, ^bb111, ^bb112
^bb111:
%905 = arith.index_cast %875 : index to i64
%906 = llvm.getelementptr %814[%905] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%904 = llvm.load %906 : !llvm.ptr -> i64
%907 = llvm.mlir.addressof @MOD : !llvm.ptr
%908 = llvm.load %907 : !llvm.ptr -> i64
%909 = arith.addi %904, %908 : i64
%910 = arith.index_cast %875 : index to i64
%911 = llvm.getelementptr %814[%910] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %909, %911 : i64, !llvm.ptr
cf.br ^bb113
^bb112:
cf.br ^bb113
^bb113:
%912 = arith.addi %875, %867 : index
cf.br ^bb108(%912 : index)
^bb110(%913: index):
%914 = llvm.mlir.addressof @STRIDE : !llvm.ptr
%915 = llvm.load %914 : !llvm.ptr -> i64
%917 = arith.index_cast %862 : index to i32
%918 = arith.trunci %915 : i64 to i32
%916 = arith.muli %917, %918 : i32
%919 = arith.extsi %916 : i32 to i64
# String concatenation: !llvm.ptr + i32
%921 = arith.constant 0 : i32
%922 = arith.extsi %921 : i32 to i64
%923 = llvm.mlir.addressof @g_ans_k : !llvm.ptr
llvm.store %922, %923 : i64, !llvm.ptr
%925 = llvm.mlir.addressof @g_cache_keys : !llvm.ptr
%926 = llvm.load %925 : !llvm.ptr -> !llvm.ptr
%927 = arith.constant 0 : i32
%928 = arith.constant 2000003 : i32
%929 = arith.constant 8 : i32
%930 = arith.muli %928, %929 : i32
%931 = arith.extsi %927 : i32 to i64
%932 = arith.extsi %930 : i32 to i64
%924 = func.call @memset(%926, %931, %932) : (!llvm.ptr, i64, i64) -> !llvm.ptr
%934 = arith.constant 0 : i32
%935 = arith.constant 1 : i32
%936 = arith.constant 1 : i32
%937 = arith.extsi %934 : i32 to i64
%938 = arith.extsi %935 : i32 to i64
%939 = arith.extsi %936 : i32 to i64
%940 = arith.index_cast %862 : index to i64
func.call @dfs(%937, %938, %939, %940, %919, %920) : (i64, i64, i64, i64, i64, !llvm.ptr) -> ()
%941 = llvm.load %845 : !llvm.ptr -> i64
%942 = llvm.mlir.addressof @g_ans_k : !llvm.ptr
%943 = llvm.load %942 : !llvm.ptr -> i64
%944 = arith.addi %941, %943 : i64
%945 = llvm.mlir.addressof @MOD : !llvm.ptr
%946 = llvm.load %945 : !llvm.ptr -> i64
%947 = arith.remsi %944, %946 : i64
llvm.store %947, %845 : i64, !llvm.ptr
%948 = arith.addi %862, %854 : index
cf.br ^bb105(%948 : index)
^bb107(%949: index):
%950 = llvm.mlir.addressof @str_1 : !llvm.ptr
%951 = llvm.load %845 : !llvm.ptr -> i64
%952 = llvm.call @printf(%950, %951) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%819) : (!llvm.ptr) -> ()
func.call @free(%814) : (!llvm.ptr) -> ()
%956 = llvm.mlir.addressof @g_cache_vals : !llvm.ptr
%957 = llvm.load %956 : !llvm.ptr -> !llvm.ptr
func.call @free(%957) : (!llvm.ptr) -> ()
%959 = llvm.mlir.addressof @g_cache_keys : !llvm.ptr
%960 = llvm.load %959 : !llvm.ptr -> !llvm.ptr
func.call @free(%960) : (!llvm.ptr) -> ()
func.call @free(%721) : (!llvm.ptr) -> ()
func.call @free(%627) : (!llvm.ptr) -> ()
func.call @free(%572) : (!llvm.ptr) -> ()
func.call @free(%435) : (!llvm.ptr) -> ()
func.call @free(%375) : (!llvm.ptr) -> ()
%966 = arith.constant 0 : i32
func.return %966 : i32
}
}