您的位置:首页 > 其它

51nod1057 N的阶乘

2016-07-13 23:16 176 查看

链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1057

题意:中文题。

分析:裸的高精度会T,压压位就过了。

代码(压4位):

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=50005;
const int mod=100000000;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=998244353;
const int INF=1000000010;
const ll MAX=1000000000000;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned long long ull;
int a
;
int main()
{
int i,j,n;
scanf("%d", &n);
a[0]=a[1]=1;
for (i=2;i<=n;i++) {
for (j=1;j<=a[0];j++) a[j]*=i;
for (j=1;j<a[0];j++) a[j+1]+=a[j]/10000,a[j]%=10000;
while (a[a[0]]>9999) {
a[a[0]+1]+=a[a[0]]/10000;
a[a[0]]%=10000;a[0]++;
}
}
printf("%d", a[a[0]]);
for (i=a[0]-1;i;i--)
if (a[i]<10) printf("000%d", a[i]);
else if (a[i]<100) printf("00%d", a[i]);
else if (a[i]<1000) printf("0%d", a[i]);
else printf("%d", a[i]);
printf("\n");
return 0;
<h3>}
</h3>

代码(压8位):

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=50005;
const int mod=100000000;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=998244353;
const int INF=1000000010;
const ll MAX=1000000000000;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned long long ull;
ll a
;
int main()
{
int j,n;
scanf("%d", &n);
a[0]=a[1]=1ll;
for (ll i=2;i<=n;i++) {
for (j=1;j<=a[0];j++) a[j]*=i;
for (j=1;j<a[0];j++) a[j+1]+=a[j]/100000000ll,a[j]%=100000000ll;
while (a[a[0]]>99999999ll) {
a[a[0]+1]+=a[a[0]]/100000000ll;
a[a[0]]%=100000000ll;a[0]++;
}
}
printf("%d", a[a[0]]);
for (j=a[0]-1;j;j--)
if (a[j]<10ll) printf("0000000%I64d", a[j]);
else if (a[j]<100ll) printf("000000%I64d", a[j]);
else if (a[j]<1000ll) printf("00000%I64d", a[j]);
else if (a[j]<10000ll) printf("0000%I64d", a[j]);
else if (a[j]<100000ll) printf("000%I64d", a[j]);
else if (a[j]<1000000ll) printf("00%I64d", a[j]);
else if (a[j]<10000000ll) printf("0%I64d", a[j]);
else printf("%I64d", a[j]);
printf("\n");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: