sqrt log sin

Time limit1sMemory limit128 MB

Summary
Precompute x_i for all i up to 10^6 using the given recurrence with floating point floors, then answer each query modulo 10^6.
Level

Medium4 of 10

Topics
Dynamic programming, Math, Implementation, Prefix sum
Solved
No attempts yet

Problem

Dohyun is doing his math homework. The assignment reads as follows.

Consider the sequence defined recursively by

x0=1x_0 = 1

xi=x⌊i−i⌋+x⌊ln⁡(i)⌋+x⌊isin⁡2(i)⌋x_i = x_{\lfloor i - \sqrt{i} \rfloor} + x_{\lfloor \ln(i) \rfloor} + x_{\lfloor i \sin^2(i) \rfloor}

Compute the value of x1000000x_{1000000}.

More generally, write a program that, given an integer ii, computes xix_i. Here ⌊y⌋\lfloor y \rfloor is the floor of yy (the greatest integer not exceeding yy), ln⁡\ln is the natural logarithm, and the argument of sin⁡\sin is measured in radians.

Input

The input consists of several test cases, one integer ii per line, where 0≤i≤1060 \le i \le 10^6.

The last line contains −1-1, which marks the end of the input and must not be processed.

Output

For each given ii, print xix_i modulo 10610^6 on its own line.

Examples4

  1. Example 1

    Input
    0
    -1
    
    Expected output
    1
    
  2. Example 2

    Input
    1
    -1
    
    Expected output
    3
    
  3. Example 3

    Input
    2
    3
    4
    5
    -1
    
    Expected output
    5
    7
    13
    21
    
  4. Example 4

    Input
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    -1
    
    Expected output
    3
    5
    7
    13
    21
    11
    23
    49
    19
    21