f(x,y) = x^2 + 5xy + 3y^2, i.e. f(x,y) = z^2 with z <= N, x,y>0, gcd(x,y)=1. N = 10^14. Two branches with inclusion-exclusion over distinct prime factors. Pure Flow port of the native C solver.
# Project Euler 769: Count primitive representations of squares by
# f(x,y) = x^2 + 5xy + 3y^2, i.e. f(x,y) = z^2 with z <= N, x,y>0, gcd(x,y)=1.
# N = 10^14. Two branches with inclusion-exclusion over distinct prime factors.
# Pure Flow port of the native C solver.
import euler.nt { isqrt }
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
function sqrt(x: f64) -> f64
}
const SQRT3: f64 = 1.7320508075688772
# Inverses mod 13.
let mut inv_mod13: ptr<i32> = null
function init_inv_mod13() -> void {
inv_mod13 = calloc(13, 4) as ptr<i32>
let mut a: i32 = 1
while a < 13 {
let mut x: i32 = 1
while x < 13 {
if (a * x) % 13 == 1 {
inv_mod13[a] = x
x = 13
}
x = x + 1
}
a = a + 1
}
}
# Linear sieve for smallest prime factor.
let mut spf_arr: ptr<i32> = null
function build_spf(n: i64) -> void {
spf_arr = calloc(n + 1, 4) as ptr<i32>
let primes: ptr<i32> = calloc(n, 4) as ptr<i32>
let mut pc: i64 = 0
let mut i: i64 = 2
while i <= n {
if spf_arr[i] == 0 {
spf_arr[i] = i as i32
primes[pc] = i as i32
pc = pc + 1
}
let mut j: i64 = 0
while j < pc {
let v: i64 = (primes[j] as i64) * i
if v > n {
j = pc
} else {
spf_arr[v] = primes[j]
if (primes[j] as i64) == (spf_arr[i] as i64) {
j = pc
} else {
j = j + 1
}
}
}
i = i + 1
}
free(primes)
}
# Distinct prime factors of n (n <= spf table size).
function distinct_prime_factors(n0: i64, out: ptr<i32>) -> i64 {
let mut cnt: i64 = 0
let mut n: i64 = n0
while n > 1 {
let p: i32 = spf_arr[n]
out[cnt] = p
cnt = cnt + 1
while n % (p as i64) == 0 {
n = n / (p as i64)
}
}
return cnt
}
# Generate squarefree divisors and Mobius values.
function gen_divisors_mu(primes: ptr<i32>, np: i64, ds: ptr<i64>, mus: ptr<i32>) -> i64 {
ds[0] = 1
mus[0] = 1
let mut len: i64 = 1
let mut i: i64 = 0
while i < np {
let p: i64 = primes[i] as i64
let mut j: i64 = 0
while j < len {
ds[j + len] = ds[j] * p
mus[j + len] = -mus[j]
j = j + 1
}
len = len * 2
i = i + 1
}
return len
}
# Count integers in [L, R] with x = rem (mod modv), 0 <= rem < modv.
function count_cong(L: i64, R: i64, modv: i64, rem0: i64) -> i64 {
let mut rem: i64 = rem0
if rem < L {
rem = rem + ((L - rem + modv - 1) / modv) * modv
}
if rem > R {
return 0
}
return 1 + (R - rem) / modv
}
# Count coprime q in [L, R] with gcd(q, n) = 1.
function count_coprime_interval(L: i64, R: i64, ds: ptr<i64>, mus: ptr<i32>, nd: i64) -> i64 {
let Lm: i64 = L - 1
let mut total: i64 = 0
let mut i: i64 = 0
while i < nd {
total = total + (mus[i] as i64) * (R / ds[i] - Lm / ds[i])
i = i + 1
}
return total
}
# Count coprime q in [L, R] with q = rem13 (mod 13).
function count_coprime_mod13(ds: ptr<i64>, mus: ptr<i32>, nd: i64, L: i64, R: i64, rem13: i32) -> i64 {
let mut total: i64 = 0
let mut i: i64 = 0
while i < nd {
let d: i64 = ds[i]
let inv: i32 = inv_mod13[(d % 13) as i32]
let m0: i32 = (rem13 * inv) % 13
let rem: i64 = d * (m0 as i64)
let modv: i64 = 13 * d
total = total + (mus[i] as i64) * count_cong(L, R, modv, rem)
i = i + 1
}
return total
}
# Binary search for max a in negative branch.
function max_abs_p_negative(N: i64) -> i64 {
let hi: i64 = isqrt(N) + 2
let mut lo: i64 = 0
while lo + 1 < hi {
let a: i64 = (lo + hi) / 2
if a == 0 {
lo = a
} else {
let mut qmin: i64 = (SQRT3 * (a as f64)) as i64 + 1
let thr: i64 = 3 * a * a
while qmin * qmin <= thr {
qmin = qmin + 1
}
let qmax: i64 = (5 * a - 1) / 2
let mut ok: i32 = 0
if qmin <= qmax {
let z: i64 = -(qmin * qmin - 5 * a * qmin + 3 * a * a)
if z <= N {
ok = 1
}
}
if ok != 0 {
lo = a
} else {
hi = a
}
}
}
return lo
}
# Main count C(N).
function C_func(N: i64) -> i64 {
let fourN: i64 = 4 * N
let mut total: i64 = 0
let primes: ptr<i32> = calloc(32, 4) as ptr<i32>
let ds: ptr<i64> = calloc(256, 8) as ptr<i64>
let mus: ptr<i32> = calloc(256, 4) as ptr<i32>
# Branch 1: p > 0, q > sqrt(3)*p, z = q^2 + 5pq + 3p^2
let pmax: i64 = isqrt(N / 3)
let mut p: i64 = 1
while p <= pmax {
let mut qmin: i64 = (SQRT3 * (p as f64)) as i64 + 1
let thr: i64 = 3 * p * p
while qmin * qmin <= thr {
qmin = qmin + 1
}
let disc: i64 = 13 * p * p + fourN
let mut qmax: i64 = (isqrt(disc) - 5 * p) / 2
if qmax >= qmin {
let pp3: i64 = 3 * p * p
while qmax >= qmin && (qmax * qmax + 5 * p * qmax + pp3) > N {
qmax = qmax - 1
}
if qmax >= qmin {
let np: i64 = distinct_prime_factors(p, primes)
let nd: i64 = gen_divisors_mu(primes, np, ds, mus)
let mut cnt: i64 = count_coprime_interval(qmin, qmax, ds, mus, nd)
if p % 13 != 0 {
let bad: i64 = count_coprime_mod13(ds, mus, nd, qmin, qmax, ((4 * p) % 13) as i32)
cnt = cnt - bad
}
total = total + cnt
}
}
p = p + 1
}
# Branch 2: p = -a < 0, sqrt(3)*a < q < 2.5a, z = -(q^2 - 5aq + 3a^2)
let amax: i64 = max_abs_p_negative(N)
let threshold: i64 = isqrt(fourN / 13)
let mut a: i64 = 1
while a <= amax {
let mut qmin: i64 = (SQRT3 * (a as f64)) as i64 + 1
let thr: i64 = 3 * a * a
while qmin * qmin <= thr {
qmin = qmin + 1
}
let mut qmax: i64 = (5 * a - 1) / 2
if qmax >= qmin {
if a > threshold {
let disc2: i64 = 13 * a * a - fourN
let s: i64 = isqrt(disc2)
let lim: i64 = (5 * a - s) / 2
if lim < qmax {
qmax = lim
}
}
while qmax >= qmin && (-(qmax * qmax - 5 * a * qmax + 3 * a * a)) > N {
qmax = qmax - 1
}
if qmax >= qmin {
let np: i64 = distinct_prime_factors(a, primes)
let nd: i64 = gen_divisors_mu(primes, np, ds, mus)
let mut cnt: i64 = count_coprime_interval(qmin, qmax, ds, mus, nd)
if a % 13 != 0 {
let rem13: i32 = ((((-4 * a) % 13) + 13) % 13) as i32
let bad: i64 = count_coprime_mod13(ds, mus, nd, qmin, qmax, rem13)
cnt = cnt - bad
}
total = total + cnt
}
}
a = a + 1
}
free(primes)
free(ds)
free(mus)
return total
}
function main() -> i32 {
init_inv_mod13()
let N: i64 = 100000000000000
let pmax: i64 = isqrt(N / 3)
let amax: i64 = max_abs_p_negative(N)
let mut maxp: i64 = pmax
if amax > maxp {
maxp = amax
}
build_spf(maxp)
let ans: i64 = C_func(N)
free(spf_arr)
free(inv_mod13)
printf("%lld\n", ans)
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);
void init_inv_mod13(void);
void build_spf_i64(int64_t n);
int64_t distinct_prime_factors_i64_ptr_i32(int64_t n0, int32_t* out);
int64_t gen_divisors_mu_ptr_i32_i64_ptr_i64_ptr_i32(int32_t* primes, int64_t np, int64_t* ds, int32_t* mus);
int64_t count_cong_i64_i64_i64_i64(int64_t L, int64_t R, int64_t modv, int64_t rem0);
int64_t count_coprime_interval_i64_i64_ptr_i64_ptr_i32_i64(int64_t L, int64_t R, int64_t* ds, int32_t* mus, int64_t nd);
int64_t count_coprime_mod13_ptr_i64_ptr_i32_i64_i64_i64_i32(int64_t* ds, int32_t* mus, int64_t nd, int64_t L, int64_t R, int32_t rem13);
int64_t max_abs_p_negative_i64(int64_t N);
int64_t C_func_i64(int64_t N);
int32_t main(void);
static const double SQRT3 = 1.7320508075688772;
/* Module statics */
static int32_t* inv_mod13 = NULL;
static int32_t* spf_arr = NULL;
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;
}
void init_inv_mod13(void) {
inv_mod13 = ((int32_t*)(calloc(13, 4)));
int32_t a = 1;
while (a < 13) {
int32_t x = 1;
while (x < 13) {
if (FLOW_CHECKED_MOD(((a * x)), (13)) == 1) {
inv_mod13[a] = x;
x = 13;
}
x = (x + 1);
}
a = (a + 1);
}
}
void build_spf_i64(int64_t n) {
spf_arr = ((int32_t*)(calloc((n + 1), 4)));
int32_t* primes = (int32_t*)(((int32_t*)(calloc(n, 4))));
int64_t pc = 0;
int64_t i = 2;
while (i <= n) {
if (spf_arr[i] == 0) {
spf_arr[i] = ((int32_t)(i));
primes[pc] = ((int32_t)(i));
pc = (pc + 1);
}
int64_t j = 0;
while (j < pc) {
int64_t v = (((int64_t)(primes[j])) * i);
if (v > n) {
j = pc;
} else {
spf_arr[v] = primes[j];
if (((int64_t)(primes[j])) == ((int64_t)(spf_arr[i]))) {
j = pc;
} else {
j = (j + 1);
}
}
}
i = (i + 1);
}
free(primes);
}
int64_t distinct_prime_factors_i64_ptr_i32(int64_t n0, int32_t* out) {
int64_t cnt = 0;
int64_t n = n0;
while (n > 1) {
int32_t p = spf_arr[n];
out[cnt] = p;
cnt = (cnt + 1);
while (FLOW_CHECKED_MOD((n), (((int64_t)(p)))) == 0) {
n = FLOW_CHECKED_DIV((n), (((int64_t)(p))));
}
}
return cnt;
}
int64_t gen_divisors_mu_ptr_i32_i64_ptr_i64_ptr_i32(int32_t* primes, int64_t np, int64_t* ds, int32_t* mus) {
ds[0] = 1;
mus[0] = 1;
int64_t len = 1;
int64_t i = 0;
while (i < np) {
int64_t p = ((int64_t)(primes[i]));
int64_t j = 0;
while (j < len) {
ds[(j + len)] = (ds[j] * p);
mus[(j + len)] = (-mus[j]);
j = (j + 1);
}
len = (len * 2);
i = (i + 1);
}
return len;
}
int64_t count_cong_i64_i64_i64_i64(int64_t L, int64_t R, int64_t modv, int64_t rem0) {
int64_t rem = rem0;
if (rem < L) {
rem = (rem + (FLOW_CHECKED_DIV(((((L - rem) + modv) - 1)), (modv)) * modv));
}
if (rem > R) {
return 0;
}
return (1 + FLOW_CHECKED_DIV(((R - rem)), (modv)));
}
int64_t count_coprime_interval_i64_i64_ptr_i64_ptr_i32_i64(int64_t L, int64_t R, int64_t* ds, int32_t* mus, int64_t nd) {
int64_t Lm = (L - 1);
int64_t total = 0;
int64_t i = 0;
while (i < nd) {
total = (total + (((int64_t)(mus[i])) * (FLOW_CHECKED_DIV((R), (ds[i])) - FLOW_CHECKED_DIV((Lm), (ds[i])))));
i = (i + 1);
}
return total;
}
int64_t count_coprime_mod13_ptr_i64_ptr_i32_i64_i64_i64_i32(int64_t* ds, int32_t* mus, int64_t nd, int64_t L, int64_t R, int32_t rem13) {
int64_t total = 0;
int64_t i = 0;
while (i < nd) {
int64_t d = ds[i];
int32_t inv = inv_mod13[((int32_t)(FLOW_CHECKED_MOD((d), (13))))];
int32_t m0 = FLOW_CHECKED_MOD(((rem13 * inv)), (13));
int64_t rem = (d * ((int64_t)(m0)));
int64_t modv = (13 * d);
total = (total + (((int64_t)(mus[i])) * count_cong_i64_i64_i64_i64(L, R, modv, rem)));
i = (i + 1);
}
return total;
}
int64_t max_abs_p_negative_i64(int64_t N) {
int64_t hi = (isqrt_i64(N) + 2);
int64_t lo = 0;
while ((lo + 1) < hi) {
int64_t a = FLOW_CHECKED_DIV(((lo + hi)), (2));
if (a == 0) {
lo = a;
} else {
int64_t qmin = (((int64_t)((SQRT3 * ((double)(a))))) + 1);
int64_t thr = ((3 * a) * a);
while ((qmin * qmin) <= thr) {
qmin = (qmin + 1);
}
int64_t qmax = FLOW_CHECKED_DIV((((5 * a) - 1)), (2));
int32_t ok = 0;
if (qmin <= qmax) {
int64_t z = (-(((qmin * qmin) - ((5 * a) * qmin)) + ((3 * a) * a)));
if (z <= N) {
ok = 1;
}
}
if (ok != 0) {
lo = a;
} else {
hi = a;
}
}
}
return lo;
}
int64_t C_func_i64(int64_t N) {
int64_t fourN = (4 * N);
int64_t total = 0;
int32_t* primes = (int32_t*)(((int32_t*)(calloc(32, 4))));
int64_t* ds = (int64_t*)(((int64_t*)(calloc(256, 8))));
int32_t* mus = (int32_t*)(((int32_t*)(calloc(256, 4))));
int64_t pmax = isqrt_i64(FLOW_CHECKED_DIV((N), (3)));
int64_t p = 1;
while (p <= pmax) {
int64_t qmin = (((int64_t)((SQRT3 * ((double)(p))))) + 1);
int64_t thr = ((3 * p) * p);
while ((qmin * qmin) <= thr) {
qmin = (qmin + 1);
}
int64_t disc = (((13 * p) * p) + fourN);
int64_t qmax = FLOW_CHECKED_DIV(((isqrt_i64(disc) - (5 * p))), (2));
if (qmax >= qmin) {
int64_t pp3 = ((3 * p) * p);
while ((qmax >= qmin && (((qmax * qmax) + ((5 * p) * qmax)) + pp3) > N)) {
qmax = (qmax - 1);
}
if (qmax >= qmin) {
int64_t np = distinct_prime_factors_i64_ptr_i32(p, primes);
int64_t nd = gen_divisors_mu_ptr_i32_i64_ptr_i64_ptr_i32(primes, np, ds, mus);
int64_t cnt = count_coprime_interval_i64_i64_ptr_i64_ptr_i32_i64(qmin, qmax, ds, mus, nd);
if (FLOW_CHECKED_MOD((p), (13)) != 0) {
int64_t bad = count_coprime_mod13_ptr_i64_ptr_i32_i64_i64_i64_i32(ds, mus, nd, qmin, qmax, ((int32_t)(FLOW_CHECKED_MOD(((4 * p)), (13)))));
cnt = (cnt - bad);
}
total = (total + cnt);
}
}
p = (p + 1);
}
int64_t amax = max_abs_p_negative_i64(N);
int64_t threshold = isqrt_i64(FLOW_CHECKED_DIV((fourN), (13)));
int64_t a = 1;
while (a <= amax) {
int64_t qmin = (((int64_t)((SQRT3 * ((double)(a))))) + 1);
int64_t thr = ((3 * a) * a);
while ((qmin * qmin) <= thr) {
qmin = (qmin + 1);
}
int64_t qmax = FLOW_CHECKED_DIV((((5 * a) - 1)), (2));
if (qmax >= qmin) {
if (a > threshold) {
int64_t disc2 = (((13 * a) * a) - fourN);
int64_t s = isqrt_i64(disc2);
int64_t lim = FLOW_CHECKED_DIV((((5 * a) - s)), (2));
if (lim < qmax) {
qmax = lim;
}
}
while ((qmax >= qmin && (-(((qmax * qmax) - ((5 * a) * qmax)) + ((3 * a) * a))) > N)) {
qmax = (qmax - 1);
}
if (qmax >= qmin) {
int64_t np = distinct_prime_factors_i64_ptr_i32(a, primes);
int64_t nd = gen_divisors_mu_ptr_i32_i64_ptr_i64_ptr_i32(primes, np, ds, mus);
int64_t cnt = count_coprime_interval_i64_i64_ptr_i64_ptr_i32_i64(qmin, qmax, ds, mus, nd);
if (FLOW_CHECKED_MOD((a), (13)) != 0) {
int32_t rem13 = ((int32_t)(FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((((-4) * a)), (13)) + 13)), (13))));
int64_t bad = count_coprime_mod13_ptr_i64_ptr_i32_i64_i64_i64_i32(ds, mus, nd, qmin, qmax, rem13);
cnt = (cnt - bad);
}
total = (total + cnt);
}
}
a = (a + 1);
}
free(primes);
free(ds);
free(mus);
return total;
}
int32_t main(void) {
init_inv_mod13();
int64_t N = 100000000000000;
int64_t pmax = isqrt_i64(FLOW_CHECKED_DIV((N), (3)));
int64_t amax = max_abs_p_negative_i64(N);
int64_t maxp = pmax;
if (amax > maxp) {
maxp = amax;
}
build_spf_i64(maxp);
int64_t ans = C_func_i64(N);
free(spf_arr);
free(inv_mod13);
printf("%lld\n", ans);
return 0;
}