Under construction

Still being built. Things may change

Oneness

Time limit2sMemory limit512 MB

Summary
Given an l-digit number n generated by a pseudo-random generator, sum the count of repunit divisors greater than 1 over all integers from 1 to n.
Level

Hard8 of 10

Topics
Number theory, Math, Implementation
Solved
No attempts yet

Problem

Define the oneness of a number xx as the number of integers d>1d > 1 that divide xx and whose decimal representation consists only of the digit 11. For example, oneness(121)=1oneness(121) = 1 and oneness(1221)=2oneness(1221) = 2.

The number nn is generated by a pseudo-random number generator. You are given two integers ll and s0s_0, where ll is the number of digits in the decimal representation of nn and s0s_0 is the seed of the generator. The digits d0d1…dl−1d_0 d_1 \ldots d_{l-1} of nn are generated by the following recurrences:

di=⌊si/1024⌋mod  10d_i = \left\lfloor s_i / 1024 \right\rfloor \mod 10

si+1=(747796405si−1403630843)mod  232s_{i+1} = (747796405 s_i - 1403630843) \mod 2^{32}

It is guaranteed that d0d_0 is non-zero. Calculate the total oneness over all integers between 11 and nn.

Input

The first line contains two integers ll and s0s_0 (1≤l≤250 0001 \le l \le 250\,000, 0≤s0<2320 \le s_0 < 2^{32}).

Output

Output the sum of the oneness over all integers between 11 and nn.

Hint

In the sample tests, nn equals 1, 11, 1221, and 9359, respectively.

Examples4

  1. Example 1

    Input
    1 1024
    
    Expected output
    0
    
  2. Example 2

    Input
    2 1048
    
    Expected output
    1
    
  3. Example 3

    Input
    4 11312
    
    Expected output
    123
    
  4. Example 4

    Input
    4 31415926
    
    Expected output
    942