Fake Prime
Time limit2sMemory limit512 MB
Find the smallest composite n > L that passes the Fermat test for every base 2..500, and print its smallest prime factor.
- Level
Hard8 of 10
- Topics
- Number theory, Math, Binary search
- Solved
- No attempts yet
Problem
Jigui met a problem that is only solvable after deciding whether a number around ten billion is prime. He wrote code that divides by every integer from 2 to , but it produced no result after an hour. A search turned up Fermat's little theorem.
For a prime and every natural number with , .
Jigui used it backwards and wrote code that reports as prime when . That code classified 561 as prime. Jigui did not give up, widened the set of bases, and settled on the following test.
Given a natural number , if every integer with satisfies , report as prime. If even one of them fails, report as composite.
Jigui checked every number up to one million by computer, submitted the answer with confidence, and was wrong again. When a prime is always reported as prime, so the only way this test errs is by reporting a composite number as prime. Call such an a counterexample.
Show Jigui a counterexample. Given an integer , find the smallest counterexample greater than and the smallest prime factor of that counterexample.
Input
The first line contains an integer . ()
Output
On the first line, print the smallest counterexample greater than and the smallest prime factor of , separated by a space. The answer is always at most , and satisfies .