Superfactorial numeral system

면접 대비

시간 제한1초메모리 제한1024 MB

요약
유리수 p/q를 a1 + a2/2! + a3/3! + ... 형태의 혼합 진법 표현으로 나타내되, k >= 2에 대해 0 <= ak < k를 만족하고 끝의 0은 생략한다.
난이도

보통10점 중 5점

유형
수학, 정수론, 그리디, 구현
정답자
아직 제출이 없습니다

문제

On the most perfect of all planets i1c5l various numeral systems are being used during programming contests. In the second division they use a superfactorial numeral system. In this system any positive integer is presented as a linear combination of numbers converse to factorials:

pq=a_1+a_22!+a_33!+…+a_nn!,.\frac{p}{q} = a\_1 + \frac{a\_2}{2!} + \frac{a\_3}{3!} + \ldots + \frac{a\_n}{n!}\\,.

Here a_1a\_1 is non-negative integer, and integers a_ka\_k for k≥2k \ge 2 satisfy 0≤a_k<k0 \le a\_k < k. The nonsignificant zeros in the tail of the superfactorial number designation pq\frac{p}{q} are rejected. The task is to find out how the rational number pq\frac{p}{q} is presented in the superfactorial numeral system.

입력

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).

출력

Single line should contain a sequence of space-separated integers a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n, forming a number designation pq\frac{p}{q} in the superfactorial numeral system. If several solution exist, output any of them.

예제3

  1. 예제 1

    입력
    1 2
    
    예상 출력
    0 1
    
  2. 예제 2

    입력
    2 10
    
    예상 출력
    0 0 1 0 4
    
  3. 예제 3

    입력
    10 2
    
    예상 출력
    5