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;
}

 

posted @ 2015-07-25 16:42  陈瑞宇  阅读(358)  评论(0编辑  收藏  举报