Duodigits. d(n) is the smallest positive multiple of n whose decimal form uses at most two distinct digits; D(k) = sum of d(n) for n <= k. For n not divisible by 10 we run ONE level-synchronous BFS across all 45 digit pairs {a,b} at once: every pair's frontier advances one level per round, so the first round that produces remainder 0 gives the shortest duodigit length, and no pair ever explores past that level. This avoids the blow-up where a pair whose smallest multiple is long would otherwise scan the whole remainder space before a better pair gets a chance. All hits at the winning level are reconstructed and the minimum value taken, which is d(n) (shorter duodigits are always smaller numbers). Numbers divisible by 10 must end in 0, so their duodigit multiple uses digits {0,d}. Writing it as 10*V, V is the smallest {0,d} duodigit divisible by m = n/10, so we BFS mod m (<= 5000) over only the 9 pairs {0,d}. The answer is 10*V. The sum is kept exactly in i128 and printed with 13 significant digits.
# Project Euler 714
# Duodigits. d(n) is the smallest positive multiple of n whose decimal
# form uses at most two distinct digits; D(k) = sum of d(n) for n <= k.
#
# For n not divisible by 10 we run ONE level-synchronous BFS across all 45
# digit pairs {a,b} at once: every pair's frontier advances one level per
# round, so the first round that produces remainder 0 gives the shortest
# duodigit length, and no pair ever explores past that level. This avoids
# the blow-up where a pair whose smallest multiple is long would otherwise
# scan the whole remainder space before a better pair gets a chance.
# All hits at the winning level are reconstructed and the minimum value
# taken, which is d(n) (shorter duodigits are always smaller numbers).
#
# Numbers divisible by 10 must end in 0, so their duodigit multiple uses
# digits {0,d}. Writing it as 10*V, V is the smallest {0,d} duodigit
# divisible by m = n/10, so we BFS mod m (<= 5000) over only the 9 pairs
# {0,d}. The answer is 10*V.
# The sum is kept exactly in i128 and printed with 13 significant digits.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
const N: i64 = 50000
# For n divisible by 10: search (up to cap_len levels) for the smallest
# {a,b}-duodigit divisible by mod. Returns its digit length, or 0 if none
# found within cap_len. Writes the exact value to out_val[0] when the
# length is <= 25, otherwise writes -1.
function bfs_ab(mod: i64, a: i64, b: i64, cap_len: i64,
seen: ptr<i64>, prv: ptr<i64>, dg: ptr<i64>, qq: ptr<i64>,
buf: ptr<i64>, ptoken: ptr<i64>, out_val: ptr<i128>) -> i64 {
let token: i64 = ptoken[0] + 1
ptoken[0] = token
let mut hit: i64 = 0
let mut hitpar: i64 = 0
let mut hitdig: i64 = 0
let mut hitlen: i64 = 0
let mut cnt: i64 = 0
let mut s: i64 = 0
while s < 2 {
let mut d: i64 = a
if s == 1 { d = b }
if d > 0 && hit == 0 {
let r: i64 = d % mod
if r == 0 {
hit = 1
hitpar = 0 - 1
hitdig = d
hitlen = 1
} else {
if seen[r] != token {
seen[r] = token
prv[r] = 0 - 1
dg[r] = d
qq[cnt] = r
cnt = cnt + 1
}
}
}
s = s + 1
}
let mut ls: i64 = 0
let mut le: i64 = cnt
let mut level: i64 = 1
while hit == 0 && ls < le && level < cap_len {
let mut ne: i64 = le
let mut i: i64 = ls
while i < le && hit == 0 {
let r: i64 = qq[i]
let mut t: i64 = 0
while t < 2 && hit == 0 {
let mut d: i64 = a
if t == 1 { d = b }
let nr: i64 = (r * 10 + d) % mod
if nr == 0 {
hit = 1
hitpar = r
hitdig = d
hitlen = level + 1
} else {
if seen[nr] != token {
seen[nr] = token
prv[nr] = r
dg[nr] = d
qq[ne] = nr
ne = ne + 1
}
}
t = t + 1
}
i = i + 1
}
ls = le
le = ne
level = level + 1
}
if hit == 0 {
out_val[0] = 0 as i128 - (1 as i128)
return 0
}
if hitlen > 25 {
out_val[0] = 0 as i128 - (1 as i128)
return hitlen
}
let mut k: i64 = 0
buf[k] = hitdig
k = k + 1
let mut c: i64 = hitpar
while c != 0 - 1 {
buf[k] = dg[c]
k = k + 1
c = prv[c]
}
let mut val: i128 = 0 as i128
let mut j: i64 = k - 1
while j >= 0 {
val = val * (10 as i128) + (buf[j] as i128)
j = j - 1
}
out_val[0] = val
return hitlen
}
# Level-synchronous BFS over all 45 digit pairs for n not divisible by 10.
# Returns d(n)'s digit length, or 0 if none found within 25 digits.
# Writes the value to out_val[0].
function bfs_all(mod: i64, pa: ptr<i64>, pb: ptr<i64>,
seen: ptr<i64>, q_pair: ptr<i8>, q_rem: ptr<i64>,
q_prv: ptr<i64>, q_dig: ptr<i8>, buf: ptr<i64>,
ptoken: ptr<i64>, out_val: ptr<i128>) -> i64 {
# single-digit duodigits (handles mod <= 9)
let mut sd: i64 = 1
while sd <= 9 {
if sd % mod == 0 {
out_val[0] = sd as i128
return 1
}
sd = sd + 1
}
let token: i64 = ptoken[0] + 1
ptoken[0] = token
let mut cnt: i64 = 0
let mut p: i64 = 0
while p < 45 {
let a: i64 = pa[p]
let b: i64 = pb[p]
let mut s: i64 = 0
while s < 2 {
let mut d: i64 = a
if s == 1 { d = b }
if d > 0 {
let r: i64 = d % mod
if r != 0 {
let key: i64 = p * mod + r
if seen[key] != token {
seen[key] = token
q_pair[cnt] = p as i8
q_rem[cnt] = r
q_prv[cnt] = 0 - 1
q_dig[cnt] = d as i8
cnt = cnt + 1
}
}
}
s = s + 1
}
p = p + 1
}
let mut ls: i64 = 0
let mut le: i64 = cnt
let mut level: i64 = 1
while ls < le && level < 25 {
let mut ne: i64 = le
let mut found: i64 = 0
let mut bestv: i128 = 0 as i128 - (1 as i128)
let mut i: i64 = ls
while i < le {
let pp: i64 = (q_pair[i] as i64)
let rem: i64 = q_rem[i]
let a: i64 = pa[pp]
let b: i64 = pb[pp]
let mut t: i64 = 0
while t < 2 {
let mut d: i64 = a
if t == 1 { d = b }
let nr: i64 = (rem * 10 + d) % mod
if nr == 0 {
let mut k: i64 = 0
buf[k] = d
k = k + 1
let mut c: i64 = i
while c != 0 - 1 {
buf[k] = (q_dig[c] as i64)
k = k + 1
c = q_prv[c]
}
let mut val: i128 = 0 as i128
let mut j: i64 = k - 1
while j >= 0 {
val = val * (10 as i128) + (buf[j] as i128)
j = j - 1
}
if found == 0 {
found = 1
bestv = val
} else {
if val < bestv { bestv = val }
}
} else {
let key: i64 = pp * mod + nr
if seen[key] != token {
seen[key] = token
q_pair[ne] = pp as i8
q_rem[ne] = nr
q_prv[ne] = i
q_dig[ne] = d as i8
ne = ne + 1
}
}
t = t + 1
}
i = i + 1
}
if found == 1 {
out_val[0] = bestv
return level + 1
}
ls = le
le = ne
level = level + 1
}
out_val[0] = 0 as i128 - (1 as i128)
return 0
}
function main() -> i32 {
let seen: ptr<i64> = calloc(N + 2, 8)
let prv: ptr<i64> = calloc(N + 2, 8)
let dg: ptr<i64> = calloc(N + 2, 8)
let qq: ptr<i64> = calloc(N + 2, 8)
let buf: ptr<i64> = calloc(64, 8)
let pa: ptr<i64> = calloc(45, 8)
let pb: ptr<i64> = calloc(45, 8)
let out_val: ptr<i128> = calloc(2, 16)
let ptoken: ptr<i64> = calloc(1, 8)
if seen == null || prv == null || dg == null || qq == null || buf == null || pa == null || pb == null || out_val == null || ptoken == null { return 1 }
# interleaved-BFS scratch (sized for 45 pairs * max mod)
let SEEN_SZ: i64 = 45 * (N + 2)
let i_seen: ptr<i64> = calloc(SEEN_SZ, 8)
let i_qrem: ptr<i64> = calloc(SEEN_SZ, 8)
let i_qprv: ptr<i64> = calloc(SEEN_SZ, 8)
let i_qpair: ptr<i8> = calloc(SEEN_SZ, 1)
let i_qdig: ptr<i8> = calloc(SEEN_SZ, 1)
if i_seen == null || i_qrem == null || i_qprv == null || i_qpair == null || i_qdig == null { return 1 }
let mut np: i64 = 0
let mut aa: i64 = 0
while aa < 10 {
let mut bb: i64 = aa + 1
while bb < 10 {
pa[np] = aa
pb[np] = bb
np = np + 1
bb = bb + 1
}
aa = aa + 1
}
let mut total: i128 = 0 as i128
let mut n: i64 = 1
while n <= N {
if n % 10 == 0 {
# n = 10*m: only pairs {0,d} can work; BFS mod m, answer is 10*V.
let m: i64 = n / 10
let mut bestlen: i64 = 1000000
let mut bestval: i128 = 0 as i128 - (1 as i128)
let mut d: i64 = 1
while d <= 9 {
let hl: i64 = bfs_ab(m, 0, d, bestlen, seen, prv, dg, qq, buf, ptoken, out_val)
if hl > 0 {
if hl <= 25 {
if hl < bestlen {
bestlen = hl
bestval = out_val[0]
} else {
if hl == bestlen {
if bestval < 0 || out_val[0] < bestval {
bestval = out_val[0]
}
}
}
} else {
if hl < bestlen {
bestlen = hl
bestval = 0 as i128 - (1 as i128)
}
}
}
d = d + 1
}
total = total + (10 as i128) * bestval
} else {
let hl: i64 = bfs_all(n, pa, pb, i_seen, i_qpair, i_qrem, i_qprv, i_qdig, buf, ptoken, out_val)
total = total + out_val[0]
}
n = n + 1
}
# scientific notation, 13 significant digits (12 after the point)
let mut tmp: i128 = total
let mut nd: i64 = 0
while tmp > (0 as i128) {
tmp = tmp / (10 as i128)
nd = nd + 1
}
let mut ex: i64 = nd - 1
let mut mant: i128 = total
if nd > 13 {
let mut shift: i64 = nd - 13
let mut pw: i128 = 1 as i128
let mut u: i64 = 0
while u < shift {
pw = pw * (10 as i128)
u = u + 1
}
mant = (total + pw / (2 as i128)) / pw
# rounding may carry into a 14th digit
let mut cap: i128 = 1 as i128
u = 0
while u < 13 {
cap = cap * (10 as i128)
u = u + 1
}
if mant >= cap {
mant = mant / (10 as i128)
ex = ex + 1
}
} else {
let mut u: i64 = nd
while u < 13 {
mant = mant * (10 as i128)
u = u + 1
}
}
let m64: i64 = mant as i64
printf("%lld.%012llde%lld\n", m64 / 1000000000000, m64 % 1000000000000, ex)
free(i_qdig)
free(i_qpair)
free(i_qprv)
free(i_qrem)
free(i_seen)
free(ptoken)
free(out_val)
free(pb)
free(pa)
free(buf)
free(qq)
free(dg)
free(prv)
free(seen)
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 bfs_ab_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i128(int64_t mod, int64_t a, int64_t b, int64_t cap_len, int64_t* seen, int64_t* prv, int64_t* dg, int64_t* qq, int64_t* buf, int64_t* ptoken, __int128* out_val);
int64_t bfs_all_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_ptr_i64_ptr_i64_ptr_i8_ptr_i64_ptr_i64_ptr_i128(int64_t mod, int64_t* pa, int64_t* pb, int64_t* seen, int8_t* q_pair, int64_t* q_rem, int64_t* q_prv, int8_t* q_dig, int64_t* buf, int64_t* ptoken, __int128* out_val);
int32_t main(void);
static const int64_t N = 50000;
int64_t bfs_ab_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i128(int64_t mod, int64_t a, int64_t b, int64_t cap_len, int64_t* seen, int64_t* prv, int64_t* dg, int64_t* qq, int64_t* buf, int64_t* ptoken, __int128* out_val) {
int64_t token = (ptoken[0] + 1);
ptoken[0] = token;
int64_t hit = 0;
int64_t hitpar = 0;
int64_t hitdig = 0;
int64_t hitlen = 0;
int64_t cnt = 0;
int64_t s = 0;
while (s < 2) {
int64_t d = a;
if (s == 1) {
d = b;
}
if ((d > 0 && hit == 0)) {
int64_t r = FLOW_CHECKED_MOD((d), (mod));
if (r == 0) {
hit = 1;
hitpar = (0 - 1);
hitdig = d;
hitlen = 1;
} else {
if (seen[r] != token) {
seen[r] = token;
prv[r] = (0 - 1);
dg[r] = d;
qq[cnt] = r;
cnt = (cnt + 1);
}
}
}
s = (s + 1);
}
int64_t ls = 0;
int64_t le = cnt;
int64_t level = 1;
while (((hit == 0 && ls < le) && level < cap_len)) {
int64_t ne = le;
int64_t i = ls;
while ((i < le && hit == 0)) {
int64_t r = qq[i];
int64_t t = 0;
while ((t < 2 && hit == 0)) {
int64_t d = a;
if (t == 1) {
d = b;
}
int64_t nr = FLOW_CHECKED_MOD((((r * 10) + d)), (mod));
if (nr == 0) {
hit = 1;
hitpar = r;
hitdig = d;
hitlen = (level + 1);
} else {
if (seen[nr] != token) {
seen[nr] = token;
prv[nr] = r;
dg[nr] = d;
qq[ne] = nr;
ne = (ne + 1);
}
}
t = (t + 1);
}
i = (i + 1);
}
ls = le;
le = ne;
level = (level + 1);
}
if (hit == 0) {
out_val[0] = (((__int128)(0)) - ((__int128)(1)));
return 0;
}
if (hitlen > 25) {
out_val[0] = (((__int128)(0)) - ((__int128)(1)));
return hitlen;
}
int64_t k = 0;
buf[k] = hitdig;
k = (k + 1);
int64_t c = hitpar;
while (c != (0 - 1)) {
buf[k] = dg[c];
k = (k + 1);
c = prv[c];
}
__int128 val = ((__int128)(0));
int64_t j = (k - 1);
while (j >= 0) {
val = ((val * ((__int128)(10))) + ((__int128)(buf[j])));
j = (j - 1);
}
out_val[0] = val;
return hitlen;
}
int64_t bfs_all_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_ptr_i64_ptr_i64_ptr_i8_ptr_i64_ptr_i64_ptr_i128(int64_t mod, int64_t* pa, int64_t* pb, int64_t* seen, int8_t* q_pair, int64_t* q_rem, int64_t* q_prv, int8_t* q_dig, int64_t* buf, int64_t* ptoken, __int128* out_val) {
int64_t sd = 1;
while (sd <= 9) {
if (FLOW_CHECKED_MOD((sd), (mod)) == 0) {
out_val[0] = ((__int128)(sd));
return 1;
}
sd = (sd + 1);
}
int64_t token = (ptoken[0] + 1);
ptoken[0] = token;
int64_t cnt = 0;
int64_t p = 0;
while (p < 45) {
int64_t a = pa[p];
int64_t b = pb[p];
int64_t s = 0;
while (s < 2) {
int64_t d = a;
if (s == 1) {
d = b;
}
if (d > 0) {
int64_t r = FLOW_CHECKED_MOD((d), (mod));
if (r != 0) {
int64_t key = ((p * mod) + r);
if (seen[key] != token) {
seen[key] = token;
q_pair[cnt] = ((int8_t)(p));
q_rem[cnt] = r;
q_prv[cnt] = (0 - 1);
q_dig[cnt] = ((int8_t)(d));
cnt = (cnt + 1);
}
}
}
s = (s + 1);
}
p = (p + 1);
}
int64_t ls = 0;
int64_t le = cnt;
int64_t level = 1;
while ((ls < le && level < 25)) {
int64_t ne = le;
int64_t found = 0;
__int128 bestv = (((__int128)(0)) - ((__int128)(1)));
int64_t i = ls;
while (i < le) {
int64_t pp = ((int64_t)(q_pair[i]));
int64_t rem = q_rem[i];
int64_t a = pa[pp];
int64_t b = pb[pp];
int64_t t = 0;
while (t < 2) {
int64_t d = a;
if (t == 1) {
d = b;
}
int64_t nr = FLOW_CHECKED_MOD((((rem * 10) + d)), (mod));
if (nr == 0) {
int64_t k = 0;
buf[k] = d;
k = (k + 1);
int64_t c = i;
while (c != (0 - 1)) {
buf[k] = ((int64_t)(q_dig[c]));
k = (k + 1);
c = q_prv[c];
}
__int128 val = ((__int128)(0));
int64_t j = (k - 1);
while (j >= 0) {
val = ((val * ((__int128)(10))) + ((__int128)(buf[j])));
j = (j - 1);
}
if (found == 0) {
found = 1;
bestv = val;
} else {
if (val < bestv) {
bestv = val;
}
}
} else {
int64_t key = ((pp * mod) + nr);
if (seen[key] != token) {
seen[key] = token;
q_pair[ne] = ((int8_t)(pp));
q_rem[ne] = nr;
q_prv[ne] = i;
q_dig[ne] = ((int8_t)(d));
ne = (ne + 1);
}
}
t = (t + 1);
}
i = (i + 1);
}
if (found == 1) {
out_val[0] = bestv;
return (level + 1);
}
ls = le;
le = ne;
level = (level + 1);
}
out_val[0] = (((__int128)(0)) - ((__int128)(1)));
return 0;
}
int32_t main(void) {
int64_t* seen = (int64_t*)(calloc((N + 2), 8));
int64_t* prv = (int64_t*)(calloc((N + 2), 8));
int64_t* dg = (int64_t*)(calloc((N + 2), 8));
int64_t* qq = (int64_t*)(calloc((N + 2), 8));
int64_t* buf = (int64_t*)(calloc(64, 8));
int64_t* pa = (int64_t*)(calloc(45, 8));
int64_t* pb = (int64_t*)(calloc(45, 8));
__int128* out_val = (__int128*)(calloc(2, 16));
int64_t* ptoken = (int64_t*)(calloc(1, 8));
if (((((((((seen == NULL || prv == NULL) || dg == NULL) || qq == NULL) || buf == NULL) || pa == NULL) || pb == NULL) || out_val == NULL) || ptoken == NULL)) {
return 1;
}
int64_t SEEN_SZ = (45 * (N + 2));
int64_t* i_seen = (int64_t*)(calloc(SEEN_SZ, 8));
int64_t* i_qrem = (int64_t*)(calloc(SEEN_SZ, 8));
int64_t* i_qprv = (int64_t*)(calloc(SEEN_SZ, 8));
int8_t* i_qpair = (int8_t*)(calloc(SEEN_SZ, 1));
int8_t* i_qdig = (int8_t*)(calloc(SEEN_SZ, 1));
if (((((i_seen == NULL || i_qrem == NULL) || i_qprv == NULL) || i_qpair == NULL) || i_qdig == NULL)) {
return 1;
}
int64_t np = 0;
int64_t aa = 0;
while (aa < 10) {
int64_t bb = (aa + 1);
while (bb < 10) {
pa[np] = aa;
pb[np] = bb;
np = (np + 1);
bb = (bb + 1);
}
aa = (aa + 1);
}
__int128 total = ((__int128)(0));
int64_t n = 1;
while (n <= N) {
if (FLOW_CHECKED_MOD((n), (10)) == 0) {
int64_t m = FLOW_CHECKED_DIV((n), (10));
int64_t bestlen = 1000000;
__int128 bestval = (((__int128)(0)) - ((__int128)(1)));
int64_t d = 1;
while (d <= 9) {
int64_t hl = bfs_ab_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i128(m, 0, d, bestlen, seen, prv, dg, qq, buf, ptoken, out_val);
if (hl > 0) {
if (hl <= 25) {
if (hl < bestlen) {
bestlen = hl;
bestval = out_val[0];
} else {
if (hl == bestlen) {
if ((bestval < 0 || out_val[0] < bestval)) {
bestval = out_val[0];
}
}
}
} else {
if (hl < bestlen) {
bestlen = hl;
bestval = (((__int128)(0)) - ((__int128)(1)));
}
}
}
d = (d + 1);
}
total = (total + (((__int128)(10)) * bestval));
} else {
int64_t hl = bfs_all_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_ptr_i64_ptr_i64_ptr_i8_ptr_i64_ptr_i64_ptr_i128(n, pa, pb, i_seen, i_qpair, i_qrem, i_qprv, i_qdig, buf, ptoken, out_val);
total = (total + out_val[0]);
}
n = (n + 1);
}
__int128 tmp = total;
int64_t nd = 0;
while (tmp > ((__int128)(0))) {
tmp = FLOW_CHECKED_DIV((tmp), (((__int128)(10))));
nd = (nd + 1);
}
int64_t ex = (nd - 1);
__int128 mant = total;
if (nd > 13) {
int64_t shift = (nd - 13);
__int128 pw = ((__int128)(1));
int64_t u = 0;
while (u < shift) {
pw = (pw * ((__int128)(10)));
u = (u + 1);
}
mant = FLOW_CHECKED_DIV(((total + FLOW_CHECKED_DIV((pw), (((__int128)(2)))))), (pw));
__int128 cap = ((__int128)(1));
u = 0;
while (u < 13) {
cap = (cap * ((__int128)(10)));
u = (u + 1);
}
if (mant >= cap) {
mant = FLOW_CHECKED_DIV((mant), (((__int128)(10))));
ex = (ex + 1);
}
} else {
int64_t u = nd;
while (u < 13) {
mant = (mant * ((__int128)(10)));
u = (u + 1);
}
}
int64_t m64 = ((int64_t)(mant));
printf("%lld.%012llde%lld\n", FLOW_CHECKED_DIV((m64), (1000000000000)), FLOW_CHECKED_MOD((m64), (1000000000000)), ex);
free(i_qdig);
free(i_qpair);
free(i_qprv);
free(i_qrem);
free(i_seen);
free(ptoken);
free(out_val);
free(pb);
free(pa);
free(buf);
free(qq);
free(dg);
free(prv);
free(seen);
return 0;
}