记录编号 |
40668 |
评测结果 |
AAAAAAAAAAAAAA |
题目名称 |
[暑假培训2012] 残酷的数学老师 |
最终得分 |
100 |
用户昵称 |
日光。 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.699 s |
提交时间 |
2012-07-18 16:02:27 |
内存使用 |
0.38 MiB |
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 15000 + 10;
int n, p;
struct bign{
int len, s[N];
bign() {
memset(s, 0, sizeof(s));
len = 1;
}
bign(int num) {
*this = num;
}
bign(const char* num) {
*this = num;
}
bign operator = (int num) {
char s[N];
sprintf(s, "%d", num);
*this = s;
return *this;
}
bign operator = (const char* num) {
len = strlen(num);
for(int i = 0; i < len; i++) s[i] = num[len-i-1] - '0';
return *this;
}
string str() const {
string res = "";
for(int i = 0; i < len; i++) res = (char)(s[i] + '0') + res;
if(res == "") res = "0";
return res;
}
void clean() {
while(len > 1 && !s[len-1]) len--;
}
bign operator * (const bign& b) {
bign c; c.len = len + b.len;
for(int i = 0; i < len; i++)
for(int j = 0; j < b.len; j++)
c.s[i+j] += s[i] * b.s[j];
for(int i = 0; i < c.len-1; i++){
c.s[i+1] += c.s[i] / 10;
c.s[i] %= 10;
}
c.clean();
return c;
}
};
int main() {
freopen("cruel1.in", "r", stdin);
freopen("cruel1.out", "w", stdout);
scanf("%d %d", &n, &p);
bign A = n;
for(int i=1; i<p; i++)
A = A * n;
string s = A.str();
for(int i=0; i<s.length(); i++)
{
printf("%c", s[i]);
if(i && (i+1) % 70 == 0) printf("\n");
}printf("\n");
return 0;
}