E. Forever Young
My birthday is coming up. Alas, I am getting old and would like to feel young again. Fortunately, I have come up with an excellent way of feeling younger: if I write my age as a number in an appropriately chosen base b, then it appears to be smaller. For in...
Problem Statement
Formatted from the contest statement text, with sample tests broken out into copyable blocks.
My birthday is coming up. Alas, I am getting old and would like to feel young again. Fortunately, I have come up with an excellent way of feeling younger: if I write my age as a number in an appropriately chosen base b, then it appears to be smaller. For instance, suppose my age in base 10 is 32. Written in base 16 it is only 20! However, I cannot choose an arbitrary base when doing this. If my age written in base b contains digits other than 0 to 9, then it will be obvious that I am cheating, which defeats the purpose. In addition, if my age written in base b is too small then it would again be obvious that I am cheating. Given my age y and a lower bound ` on how small I want my age to appear, find the largest base b such that y written in base b contains only decimal digits, and is at least ` when interpreted as a number in base 10.
Input
The input consists of a single line containing two base 10 integers y (10 ≤ y ≤ 1018 – yes, I am very old) and ` (10 ≤ ` ≤ y).
Output
Display the largest base b as described above.
Sample Tests
32 20 16 2016 100 42 Editorial
The solution write-up is rendered from the LaTeX source, with equations kept live through MathJax.
Key Observations
Write the structural observations that make the problem tractable.
State any useful invariant, monotonicity property, graph interpretation, or combinatorial reformulation.
If the constraints matter, explain exactly which part of the solution they enable.
Algorithm
Describe the data structures and the state maintained by the algorithm.
Explain the processing order and why it is sufficient.
Mention corner cases explicitly if they affect the implementation.
Correctness Proof
We prove that the algorithm returns the correct answer.
Lemma 1.
State the first key claim.
Proof.
Provide a concise proof.
Lemma 2.
State the next claim if needed.
Proof.
Provide a concise proof.
Theorem.
The algorithm outputs the correct answer for every valid input.
Proof.
Combine the lemmas and finish the argument.
Complexity Analysis
State the running time and memory usage in terms of the input size.
Implementation Notes
Mention any non-obvious implementation detail that is easy to get wrong.
Mention numeric limits, indexing conventions, or tie-breaking rules if relevant.
Code
C++ solution used for this page.
#include <bits/stdc++.h>
using namespace std;
namespace {
void solve() {
// Fill in the full solution logic for the problem here.
}
} // namespace
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Source Files and Assets
Raw files are still available here when you want the original TeX, C++, or statement assets.
Show raw files
competitive_programming/icpc/2016/E-forever-young/solution.texC++ implementationcompetitive_programming/icpc/2016/E-forever-young/solution.cppStatement textcompetitive_programming/icpc/2016/E-forever-young/statement.txtStatement PDFcompetitive_programming/icpc/2016/E-forever-young/statement.pdfMetadatacompetitive_programming/icpc/2016/E-forever-young/meta.jsonYear packetcompetitive_programming/icpc/2016/contest_problems.pdf