Under construction

Still being built. Things may change

Perfect Square Republic

Time limit5sMemory limit128 MB

Summary
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 DD from Independence Day until today is a perfect square.
  • DD can be written as a product of distinct natural numbers that are each at most nn.
  • DD is the largest number satisfying the two conditions above.

Because one year in this republic lasts 1,000,000,0071{,}000{,}000{,}007 days, the people want to know DD modulo 1,000,000,0071{,}000{,}000{,}007. Note that they want the remainder of the largest DD itself, not the largest possible remainder.

For each nn, write a program that prints the largest such DD modulo 1,000,000,0071{,}000{,}000{,}007.

Input

The input consists of several test cases. Each test case is a single line containing one integer nn. (1≤n≤10,000,0001 \le n \le 10{,}000{,}000)

The input ends when 00 is given.

Output

For each test case, print the largest valid DD modulo 1,000,000,0071{,}000{,}000{,}007, one value per line.

Examples1

  1. Example 1

    Input
    4
    9348095
    6297540
    0
    
    Expected output
    4
    177582252
    644064736