Attractors of an aliquot-like odd-part divisor map
/app/cpu/main.cpp is the source of a multicore CPU program (C++17, OpenMP).
The program takes one input-file path (PROGRAM INPUT_FILE) and writes its result to stdout.
What the program computes
For a positive integer n write n = 2^k * m with m odd. Define
T(n) = sigma(m) - m + 2*tau(n) + k
where sigma is the sum of divisors and tau the number of divisors (of n, not m).
For example T(1) = 2, T(2) = 5, T(5) = 5, T(12) = 1 + 12 + 2 = 15.
For every start n in the query interval [L, L+W) the program builds the trajectory
x_0 = n, x_{j+1} = T(x_j) and stops at the first j with x_j = x_i for some i < j.
Then mu = i (tail length), lambda = j - i (cycle length) and the attractor is the
smallest value in the cycle x_i .. x_{j-1}. Two special classes exist (they do not
occur for the hidden input ranges but are part of the specification):
- if some
T(x_{j-1}) > 2^60, the start isescapewithmu = j,lambda = 0; - if no repeat occurs among
x_0 .. x_199, the start islongwithmu = 200,lambda = 0.
Input format
Q
L_1 W_1
...
1 <= L, 0 <= W, L + W - 1 <= 10^13.
Output format
Per query:
query L W
sum_mu SMU sum_lambda SLAM hash HASH
max_mu MU at N (or "max_mu - at -" when W = 0)
attractors K
A_1 COUNT_1
...
SMU,SLAM: sums ofmuandlambdaover all starts (decimal, mod 2^64).HASH: sum over starts ofmix64(n XOR mix64(A + (mu << 32) + lambda))mod 2^64, withAthe attractor id (2^64-1for escape,2^64-2for long) andmix64the SplitMix64 finaliser in the CPU source.max_mu: the largestmuand the smallest start achieving it.attractors: number of distinct attractor ids, then one line per id in increasing numeric order (escape/long print as the wordsescape/long, after all numbers).
Hidden inputs
Correctness inputs (8 files, 2 to 5 queries each) include W = 0, W = 1, L = 1,
intervals ending at 10^13, intervals around 2^40, 10^12 and 3^26, and random
intervals with W <= 8000 and L >= 10^9. The timing input has 3 queries with W
uniform in [3.5*10^6, 4.5*10^6] and L uniform in [10^11, 10^13 - W + 1].
Your task
Port this program to CUDA in /app/gpu/main.cu: same command line (PROGRAM INPUT_FILE),
same output on stdout. Then make it as fast as you can on the GPU while keeping the output correct.
The main computation must execute on the GPU. Renaming CPU code to .cu, running a
CPU fallback, or launching a dummy kernel while computing the answer on the CPU does not satisfy this task.
The CPU source is the specification: when this text and the code disagree, the code wins.
This sandbox is for writing the source only: it has g++ and the CPU program, but no CUDA
compiler and no GPU. Compilation, execution and verification happen later on an H100 in a
separate verifier, and a port that does not compile is rejected, so check your logic against
the CPU program before you finish (for example by emulating your kernels on the host).
How your port is verified
- Only
/app/gpu/main.cuis collected. It is compiled withnvcc -O3 -arch=sm_90 -std=c++17 -o port /app/gpu/main.cu; no extra libraries are linked. The CUDA runtime and the header-only libraries that ship with the CUDA toolkit (CUB, Thrust, libcu++) are allowed. - Your source must not contain any of:
system(,popen(,fork(,exec*,dlopen(,getenv(,#include <filesystem>,/tests/,/proc/. The program may read only the input file it is given. - Verification runs on one H100 in a fresh container without network. Hidden inputs are generated with a fresh random seed at verification time.
- Correctness: every hidden input (small edge cases plus a large timing input) must pass. Your output must be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout is rejected.
- GPU execution is checked: a port that computes its answer on the CPU is rejected even when its output is correct.
- Speed: The timing input has 3 intervals of about 4e6 consecutive start values each (about 1.2e7 trajectories), starting at random points between 1e11 and 1e13.
/app/inputs/timing_example.inhas the shape and size of the hidden timing input. Your port is timed against a reference GPU port on it; the faster your port, the higher its score. /app/inputs/holds public input examples for understanding the input format.