Grimm's Conjecture
Time limit2sMemory limit128 MB
Assign to each number in a composite interval a distinct prime divisor, choosing the lexicographically smallest assignment, for many test cases with H up to 10^10.
- Level
Hard8 of 10
- Topics
- Number theory, Math, Greedy
- Solved
- No attempts yet
Problem
Grimm's conjecture states that whenever you are given a block of consecutive composite numbers, you can assign to each of them a distinct prime that divides it.
Formally, if are all composite, then there exist distinct primes such that divides . ()
Given an interval of consecutive composite numbers, write a program that, for each of , finds one distinct prime dividing it.
If several assignments are possible, output the lexicographically smallest one: make the prime assigned to the first number as small as possible; among those, make the prime assigned to the second number as small as possible; then the third, and so on.
Input
The input consists of several test cases. Each test case is a single line with two integers and . ()
Every number in the interval is guaranteed to be composite.
The last line contains two zeros and must not be processed.
Output
For each test case, print on one line the prime assigned to each number from to , separated by single spaces.