CF Gym 100637J Superfactorial numeral system (构造)

题意:给一个式子,ak,k>2时,0<=ak<k;ai都是整数,给你p,q让你求一组ak。

题解:构造,每次除掉q取整得到ai,然后减一减

#include<cstdio>

#include<cmath>

#include<vector>

#include<map>

#include<set>

#include<algorithm>



using namespace std;

typedef unsigned long long ull;



int main()

{

    ull p,q;

    scanf("%I64u%I64u",&p,&q);

    ull fac = 2;

    ull ai = p/q;

    printf("%I64u",ai);

    p = (p-ai*q)*(fac);

    while(p){

        ai = p/q;

        printf(" %I64u",ai);

        p = (p - ai*q)*(++fac);

    }

    return 0;

}

 

你可能感兴趣的:(System)