题目链接:http://ac.jobdu.com/problem.php?pid=1076
详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus
参考代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <cmath>
#define MAX_SIZE 10010
using namespace std; int n;
int pos[MAX_SIZE]; int main(){
while(~scanf("%d",&n)){
memset(pos,,sizeof(pos));
if(==n){
printf("1\n");
continue;
}
int i,j;
int length = ;
pos[]=;
for(i = ; i <= n ; i++){
int carry = ;
for(j = ; j < length ; j++){
pos[j] = pos[j] * i + carry;
if(pos[j]>=){
carry = pos[j]/;
pos[j] = pos[j]%;
}
else{
carry = ;
}
}
while(carry!=){
pos[length++] = carry % ;
carry/=;
}
}
for(i = MAX_SIZE ; i >= ; i--){
if(pos[i]!=)
break;
}
for(j = i ; j >= ; j--){
printf("%d",pos[j]);
}
printf("\n");
}
return ;
}
/**************************************************************
Problem: 1076
User: zpfbuaa
Language: C++
Result: Accepted
Time:1480 ms
Memory:1560 kb
****************************************************************/