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 source generation only. Write /app/gpu/main.cu; compilation,
execution and verification are performed later in a separate verifier environment.
How you are scored
- 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. - GPU verification uses the backend selected for this run: an H100 attached to the separate verifier, or a remote H100 worker. Hidden inputs use a fresh random seed.
- Correctness: every hidden input (small edge cases plus the timing input) must pass. Your output must be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout gives reward 0.
- GPU execution: a separate, untimed CUPTI check must observe completed GPU kernel activity on the hidden timing input. A CPU-only submission receives reward 0 even if 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. Your port and our GPU reference are each run on it
once to warm up and then 5 times, interleaved; the time is the wall clock of the whole process
(including CUDA initialisation, input parsing and output). When correct,
reward = min(2, t_reference / t_yours)using the medians. /app/inputs/holds public input examples for understanding the input format.