Perfect Square Republic
Time limit5sMemory limit128 MB
Find, for each n, the largest perfect square expressible as a product of distinct integers up to n, output mod 1e9+7 for many queries up to n=10^7.
- Level
Hard8 of 10
- Topics
- Number theory, Math, Greedy, Sorting
- Solved
- No attempts yet
Problem
The people of the Perfect Square Republic celebrate their Independence Day every year. However, independence happened so long ago that no one remembers the exact date anymore. All that remains in people's memory is the following.
- The number of days from Independence Day until today is a perfect square.
- can be written as a product of distinct natural numbers that are each at most .
- is the largest number satisfying the two conditions above.
Because one year in this republic lasts days, the people want to know modulo . Note that they want the remainder of the largest itself, not the largest possible remainder.
For each , write a program that prints the largest such modulo .
Input
The input consists of several test cases. Each test case is a single line containing one integer . ()
The input ends when is given.
Output
For each test case, print the largest valid modulo , one value per line.