51nod 1057 高精度乘法
来源:互联网 发布:去重sql语句 distinct 编辑:程序博客网 时间:2024/04/20 10:51
题目传送门: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1057
题意:题目就是要求n的阶乘,但n <= 100000,显然要用到乘法模拟
大致思路就是将一个数分段储存起来,由于此题n最大是100000,所以就按5位数字存在一个元素当中。每次乘的时候就用当前数组中元素从低位到高位分别去乘,该进位的进位就行了。
代码如下:
#include <iostream>#include <algorithm>#include <cstring>#include <stdio.h>#include <string>#define ll long longusing namespace std;const int maxn = 10005;const int mod = 100000;int main(){ int a[maxn];//用来存大数 int n,len = 1; memset(a,0,sizeof(a)); a[0] = 1; cin >> n;// 要阶乘的数n int c = 0; int i,j; for(i=2;i<=n;i++){//从2开始乘直到n c = 0; for(j=0;j<len;j++){//让a数组中存的数分段跟i相乘 a[j] = (c += a[j] * i) % mod; // c 用来判断是否需要进位 ,将a[j]跟i相乘后膜_max存起来 c /= mod; } if((a[j] = c) > 0) len++;//如果c/mod后还 >0 说明需要进位 } printf("%d",a[--len]); while(len >= 1) printf("%05d",a[--len]);//输出时按一个元素五位输出 return 0;}
0 0
- 51nod 1057 高精度乘法
- 51Nod 大数乘法
- 51nod 大数乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 这是我的第一篇博文
- MySQL常用命令
- linked-list-cycle-ii
- 使用Linux工作之Fedora KDE
- linux内核态和用户态
- 51nod 1057 高精度乘法
- 单例设计模式
- 面向对象与面向过程的区别?
- POJ2960 S-Nim(博弈论:sg函数)
- 前端笔试(三)
- 第四周项目3-单链表应用(2)
- HDU1576 A/B 求乘法逆元模版
- (九)ArcGIS API For Javascript调用结果地图服务
- ViewPager冲突之(ViewPager与ViewPager+Fragment滑动栏冲突)