记录编号 |
187274 |
评测结果 |
AAAAWAWEEE |
题目名称 |
Asm.Def大点兵 |
最终得分 |
50 |
用户昵称 |
Skyo |
是否通过 |
未通过 |
代码语言 |
C++ |
运行时间 |
1.361 s |
提交时间 |
2015-09-18 08:48:55 |
内存使用 |
0.30 MiB |
显示代码纯文本
#include <cstdio>
#include <algorithm>
#include <cstring>
#define M 505
#define P 10000
typedef long long L;
using namespace std;
L n, m, p;
char s[M];
struct BigInt{
L a[M], h;
bool neg;
BigInt(){
h = neg = 0;
memset(a, 0, sizeof a);
}
void read(){
memset(s, 0, sizeof s);
scanf("%s", s+1);
int len = strlen(s+1);
h = 1;
for(int i = len, j = 1; i; i--, j *= 10){
if(j == P){
j = 1;
h++;
}
a[h] += (s[i]-'0')*j;
}
}
void read(L k){
while(k){
a[++h] = k % P;
k /= P;
}
}
bool operator < (BigInt k) const {
if(h > k.h) return 0;
if(h < k.h) return 1;
for(int i = h; i; i--){
if(a[i] > k.a[i]){
return 0;
}
if(a[i] < k.a[i]){
return 1;
}
}
return 0;
}
bool operator > (BigInt k) const {
if(h > k.h) return 1;
if(h < k.h) return 0;
for(int i = h; i; i--){
if(a[i] > k.a[i]){
return 1;
}
if(a[i] < k.a[i]){
return 0;
}
}
return 0;
}
bool operator == (BigInt k) const {
if(h != k.h) return 0;
for(int i = h; i; i--){
if(a[i] != k.a[i]) return 0;
}
return 1;
}
BigInt operator + (BigInt k) const {
BigInt res = *this;
res.h = max(res.h, k.h);
for(int i = 1; i <= res.h; i++){
res.a[i] += k.a[i];
res.a[i+1] += res.a[i] / P;
res.a[i] %= P;
}
while(res.a[res.h+1]) res.h++;
return res;
}
BigInt operator - (BigInt k) const {
BigInt res = *this;
for(int i = 1; i <= k.h; i++){
res.a[i] -= k.a[i];
if(res.a[i] < 0){
res.a[i] += P;
res.a[i+1]--;
}
}
while(!res.a[res.h] && res.h) res.h--;
return res;
return res;
}
BigInt operator * (BigInt k) const {
BigInt res;
if(!h || !k.h) return res;
for(int i = 1; i <= h; i++)
for(int j = 1; j <= k.h; j++){
res.a[i+j-1] += a[i] * k.a[j];
res.a[i+j] += res.a[i+j-1] / P;
res.a[i+j-1] %= P;
}
res.h = h + k.h + 2;
while(!res.a[res.h] && res.h) res.h--;
return res;
}
BigInt operator * (L k) const {
BigInt res;
if(!h || !k) return res;
for(int i = 1; i <= h; i++){
res.a[i] += a[i] * k;
res.a[i+1] += res.a[i] / P;
res.a[i] %= P;
}
res.h = h + 2;
while(!res.a[res.h] && res.h) res.h--;
return res;
}
BigInt operator / (BigInt k) const {
BigInt res, two;
two.h = 1;
two.a[1] = 2;
#define RES k*res+k
while(RES < *this || RES == *this){
BigInt t;
t.h = t.a[1] = 1;
while(k*(t+res)*two < *this || k*(t+res)*two == *this){
t = t * two;
}
res = res + t;
}
return res;
}
BigInt operator / (L k) const {
BigInt res;
L x = 0;
for(int i = h; i; i--){
res.a[i] = (x*P + a[i]) / k;
x = (x*P + a[i]) % k;
}
res.h = h;
while(!res.a[res.h] && res.h) res.h--;
return res;
}
BigInt operator % (L k) const {
BigInt res = *this - (*this / k) * k;
while(!res.a[res.h] && res.h) res.h--;
return res;
}
void print(){
if(!h) {
printf("0");
return;
}
if(neg) printf("-");
printf("%lld", a[h]);
for(int i = h-1; i; i--){
int k = a[i], len = 1;
while(k){
len *= 10;
k /= 10;
}
if(len==1) len *= 10;
while(len < P){
printf("0");
len *= 10;
}
printf("%lld", a[i]);
}
printf("\n");
}
}ans, a;
int main()
{
freopen("appoint.in","r",stdin);
freopen("appoint.out","w",stdout);
scanf("%lld %lld %lld", &n, &m, &p);
m = n - m + 1;
ans.read(m++);
while(m <= n){
BigInt K;
K.read(m);
ans = ans * K;
ans = ans % p;
m++;
}
ans = ans % p;
ans.print();
return 0;
}