单精度和高精度乘法
来源:互联网 发布:电子竞技数据分析 编辑:程序博客网 时间:2024/06/10 12:51
lightOJ-1024
#include<cmath>#include<cstdio>#include<cstring>#include<iostream>using namespace std;const int MAXN = 100010;int ans[MAXN], cnt[MAXN], len;int fun(int x,int y)//x代表因子 y代表这个因子出现的次数{ int t=1; for(int i=1; i<=y; i++) t*=x; return t;}void multiply(int fact){ //cout << fact << "**" << endl; for(int i = 0; i < len; i ++) ans[i] *= fact;//先把每位乘以每一个新的因子 for(int i = 0; i < len; i ++)//再重新分解一遍只储存每个位数 { ans[i+1] += ans[i]/10; ans[i] %= 10; }// for(int i=len;i>=0;i--)// cout << ans[i] <<":";// cout << endl; int tmp = ans[len]; while(tmp)//分解最后那个数,因为最后可能不是一位数,大数长度增加就是在这里记录的 { ans[len++] = tmp%10; tmp /= 10; }// for(int i=len;i>=0;i--)// cout << ans[i] <<"^";// cout << endl;}int main(){ int t, CASE(0), n, tmp; scanf("%d", &t); while(t--) { scanf("%d", &n); memset(cnt, 0, sizeof cnt); memset(ans, 0, sizeof ans); for(int i = 0; i < n; i ++) { scanf("%d", &tmp); int fact = 2; while(tmp != 1)//找出所有的因子,并储存因子出现的次数 { int num = 0; while(tmp % fact == 0) num ++, tmp /= fact; cnt[fact] = max(cnt[fact], num);//记录出现次数 fact++; } } ans[0] = len = 1; for(int i = 2; i <= 10000; i ++) if(cnt[i]) multiply(fun(i, cnt[i])); printf("Case %d: ", ++CASE);//上面的循环是把所有最高次因子乘起来 for(int i = len - 1; i > 0; i --) printf("%d", ans[i]);//按位输出大数 printf("%d\n", ans[0]); } return 0;}/*5 4 3 5 7 11*/网上学来的,自己加了注释便于理解。->http://blog.csdn.net/zyz_3_14159/article/details/52810165
阅读全文
0 0
- 单精度和高精度乘法
- 高精度乘单精度
- 高精度除单精度
- 高精度除以单精度 和 高精度对单精度取模
- 高精度乘法与高精度除低精度
- 高精度乘单精度 poj1001
- 高精度加法和高精度乘法
- 高精度乘法和阶乘
- 高精度乘法和除法
- 高精度加法和乘法
- 高精度乘以单精度 hdu1042 N!
- lightoj 1024 (高精度乘单精度)
- LightOJ1024-Eid-高精度乘单精度
- 单精度和双精度
- 双精度,单精度和半精度
- 单精度浮点数乘法的实现
- 超大整数乘法模板(高精度乘以低精度)
- 高精度(乘法和加法)
- zimg 3.1 安装
- Pycharm 2017 激活
- linux如何安装gdb-server
- jquery 设置button可用不可用以及隐藏和显示
- 机器学习业务实践之路
- 单精度和高精度乘法
- 欢迎使用CSDN-markdown编辑器
- oracle触发器
- 3-4 计算长方形的周长和面积 sdut-oj
- getspent、setspent和endspent运行出错
- 自定义view解锁
- swipeRefreshLayout 上拉加载 下拉刷新
- Objective-C知识汇总
- 测试去空格