[AHOI2002]网络传输
阅读原文时间:2023年07月10日阅读:1

这道题根据题意,易知k的幂与p的二进制形式有关系,然后再一波高精度即可。(这里我用$n、k$代替了$k、p$)

#include
#include
#include
#include

using namespace std;

#define re register
#define rep(i, a, b) for (re int i = a; i <= b; ++i) #define repd(i, a, b) for (re int i = a; i >= b; --i)
#define maxx(a, b) a = max(a, b);
#define minn(a, b) a = min(a, b);
#define LL long long
#define inf (1 << 30)

inline int read() {
int w = , f = ; char c = getchar();
while (!isdigit(c)) f = c == '-' ? - : f, c = getchar();
while (isdigit(c)) w = (w << ) + (w << ) + (c ^ ''), c = getchar();
return w * f;
}

const int maxl = , base = ;

int n, k;

int a[maxl], sum[maxl];

void time() {
int x = ;
rep(i, , a[]) a[i] = a[i] * n + x, x = a[i] / base, a[i] %= base;
if (x) a[++a[]] = x;
}

void add() {
int x = ; maxx(sum[], a[]);
rep(i, , sum[]) sum[i] += a[i] + x, x = sum[i] / base, sum[i] %= base;
if (x) sum[++sum[]] = x;
}

int main() {
freopen("ques.in", "r", stdin);
freopen("ques.out", "w", stdout);

 n = read(), k = read();  
 a\[\] = a\[\] = sum\[\] = ;

 while (k) {  
     if (k & ) add();  
     k >>= ;  
     time();  
 }

 repd(i, sum\[\], )  
     if (i == sum\[\]) printf("%d", sum\[i\]); else printf("%04d", sum\[i\]);

 return ;  

}