Under construction

Still being built. Things may change

Superfactorial Numeral System

Interview

Time limit1sMemory limit1024 MB

Summary
Convert the fraction p/q into superfactorial digits a_1, a_2, ... where each a_k is below k and is weighted by 1/k!.
Level

Medium4 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

On the most perfect planet i1c5l, programming contests use various numeral systems. In the second division, contestants use the superfactorial numeral system. In this system, a number is written as a linear combination of reciprocals of factorials.

pq=a1+a22!+a33!+…+ann!\frac{p}{q} = a_1 + \frac{a_2}{2!} + \frac{a_3}{3!} + \ldots + \frac{a_n}{n!}

Here a1a_1 is a non-negative integer, and each integer aka_k with k≥2k \ge 2 satisfies 0≤ak<k0 \le a_k < k. Nonsignificant zeros at the tail of a superfactorial representation are omitted. Find the representation of the rational number pq\frac{p}{q} in the superfactorial numeral system.

Input

A single line contains two space-separated integers pp and qq (1≤p≤1061 \le p \le 10^6, 1≤q≤1061 \le q \le 10^6).

Output

A single line with the space-separated integers a1,a2,…,ana_1, a_2, \ldots, a_n that form the superfactorial representation of pq\frac{p}{q}. If several solutions exist, print any of them.

Examples3

  1. Example 1

    Input
    1 2
    
    Expected output
    0 1
    
  2. Example 2

    Input
    2 10
    
    Expected output
    0 0 1 0 4
    
  3. Example 3

    Input
    10 2
    
    Expected output
    5