Overview
In this challenge, you will be given two numbers which are both a small offset larger than a multiple of a medium-size number. You must output a medium-sized number that is almost a divisor of both of the numbers, except for a small offset.
The size of the numbers involved will be parameterized by a difficulty parameter, l
. Your objective is to solve the problem for the largest possible l
in under 1 minute.
Setup
In a given problem, there will be a secret number, p
, which will be a random l^2
(l*l
) bit number. There will be two multipliers, q1, q2
, which will be random l^3
bit numbers, and there will be two offsets, r1, r2
, which will be random l
bit numbers.
The input to your program will be x1, x2
, defined as:
x1 = p * q1 + r1
x2 = p * q2 + r2
Here's a program to generate test cases, in Python:
from random import randrange
from sys import argv
l = int(argv[1])
def randbits(bits):
return randrange(2 ** (bits - 1), 2 ** bits)
p = randbits(l ** 2)
print(p)
for i in range(2):
q_i = randbits(l ** 3)
r_i = randbits(l)
print(q_i * p + r_i)
The first line of output is a possible solution, while the second and third lines are the input that your program will be given.
Your Program
Given x1
, x2
and l
, you must find a l^2
bit number p'
such that x1 % p'
and x2 % p'
are both l
bit numbers. p
will always work, though there may be other possibilities. Here's a function to verify a solution:
def is_correct(x1, x2, l, p_prime):
p_prime_is_good = p_prime >> (l**2 - 1) and not p_prime >> l ** 2
x1_is_good = (x1 % p_prime) >> (l-1) and not (x1 % p_prime) >> l
x2_is_good = (x2 % p_prime) >> (l-1) and not (x2 % p_prime) >> l
return bool(p_prime_is_good and x1_is_good and x2_is_good)
Example
Suppose l
is 3. The generator program picks a 9-bit number for p
, which in this case is 442
. The generator picks two 3
bit numbers for r1, r2
, which are 4, 7
. The generator picks two 27
bit numbers for q1, q2
, which are 117964803, 101808039
. Because of these choices, x1, x2
are 52140442930, 44999153245
.
Your program would be given 52140442930, 44999153245
as input, and must output a 9-bit number (in the range [256, 511]
) such that 52140442930
and 44999153245
modulo that number give 3 bit numbers (in the range [4, 7]
). 442
is the only such value in this case, so your program would have to output 442
.
More examples
l = 2
x1 = 1894
x2 = 2060
p = 11
No other p'.
l = 3
x1 = 56007668599
x2 = 30611458895
p = 424
No other p'.
l = 6
x1 = 4365435975875889219149338064474396898067189178953471159903352227492495111071
x2 = 6466809655659049447127736275529851894657569985804963410176865782113074947167
p = 68101195620
I don't know whether there are other p'.
l = 12
x1 = 132503538560485423319724633262218262792296147003813662398252348727558616998821387759658729802732555377599590456096450977511271450086857949046098328487779612488702544062780731169071526325427862701033062986918854245283037892816922645703778218888876645148150396130125974518827547039720412359298502758101864465267219269598121846675000819173555118275197412936184329860639224312426860362491131729109976241526141192634523046343361089218776687819810873911761177080056675776644326080790638190845283447304699879671516831798277084926941086929776037986892223389603958335825223
x2 = 131643270083452525545713630444392174853686642378302602432151533578354175874660202842105881983788182087244225335788180044756143002547651778418104898394856368040582966040636443591550863800820890232349510212502022967044635049530630094703200089437589000344385691841539471759564428710508659169951391360884974854486267690231936418935298696990496810984630182864946252125857984234200409883080311780173125332191068011865349489020080749633049912518609380810021976861585063983190710264511339441915235691015858985314705640801109163008926275586193293353829677264797719957439635
p = 12920503469397123671484716106535636962543473
I don't know whether there are other p'.
l = 12
x1 = 202682323504122627687421150801262260096036559509855209647629958481910539332845439801686105377638207777951377858833355315514789392768449139095245989465034831121409966815913228535487871119596033570221780568122582453813989896850354963963579404589216380209702064994881800638095974725735826187029705991851861437712496046570494304535548139347915753682466465910703584162857986211423274841044480134909827293577782500978784365107166584993093904666548341384683749686200216537120741867400554787359905811760833689989323176213658734291045194879271258061845641982134589988950037
x2 = 181061672413088057213056735163589264228345385049856782741314216892873615377401934633944987733964053303318802550909800629914413353049208324641813340834741135897326747139541660984388998099026320957569795775586586220775707569049815466134899066365036389427046307790466751981020951925232623622327618223732816807936229082125018442471614910956092251885124883253591153056364654734271407552319665257904066307163047533658914884519547950787163679609742158608089946055315496165960274610016198230291033540306847172592039765417365770579502834927831791804602945514484791644440788
p = 21705376375228755718179424140760701489963164
Scoring
As mentioned above, your program's score is the highest l
that the program completes in under 1 minute. More specifically, your program will be run on 5 random instances with that l
, and it must output a correct answer on all 5, with an average time under 1 minute. A program's score will be the highest l
that it succeeds on. Tiebreaker will be average time on that l
.
To give you an idea of what scores to aim for, I wrote a very simple brute-force solver. It got a score of 5. I wrote a much fancier solver. It got a score of 12 or 13, depending on luck.
Details
For perfect comparability across answers, I will time submissions on my laptop to give canonical scores. I will also run the same randomly chosen instances on all submissions, to alleviate luck somewhat. My laptop has 4 CPUs, i5-4300U CPU @ 1.9 GHz, 7.5G of RAM.
Feel free to post a provisional score based on your own timing, just make it clear whether it's provisional or canonical.
May the fastest program win!
l^2
bit number that'sl
-bits away from being a factor of both numbers works. There's typically only one, however. \$\endgroup\$