Light OJ 1024(高精度乘)
来源:互联网 发布:java常用api详解 编辑:程序博客网 时间:2024/06/18 17:14
题目分析
这道题要求n个数的最小公倍数,但是需要进行高精度进行处理。
#include <map>#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1e6+100;map <int, int> M;int ans[maxn], len;void mul(int x){ for(int i = 0; i < len; i++) ans[i] *= x; for(int i = 0; i < len; i++){ ans[i+1] += ans[i]/10; ans[i] = ans[i]%10; } int temp = ans[len]; while(temp){ ans[len++] = temp%10; temp /= 10; }}int quick_pow(int a, int b){ int ret = 1; while(b){ if(b&1) ret *= a; b >>= 1; a = a*a; } return ret;}int main(){ int T, n, x; scanf("%d", &T); for(int kase = 1; kase <= T; kase++){ scanf("%d", &n); M.clear(); memset(ans, 0, sizeof(ans)); for(int i = 1; i <= n; i++){ scanf("%d", &x); int len = sqrt(0.5 + x); for(int j = 2; j <= len; j++) if(x%j == 0){ int tot = 0; while(x%j==0){ tot++; x /= j; } if(tot > M[j]) M[j] = tot; } if(x != 1 && M[x] == 0) M[x] = 1; } ans[0] = len = 1; for(map <int, int>::iterator it = M.begin(); it != M.end(); it++) mul(quick_pow(it->first, it->second)); printf("Case %d: ", kase); for(int i = len-1; i >= 0; i--) printf("%d", ans[i]); printf("\n"); } return 0;}
0 0
- Light OJ 1024(高精度乘)
- Light 1024 - Eid (高精度)
- 【高精度 乘】
- lightoj 1024 (高精度乘单精度)
- light oj
- light oj
- Light OJ
- Light OJ
- 高精度加减乘模版
- 高精度加减乘运算
- 高精度 加 减 乘
- 高精度乘单精度
- 【模板】高精度--加减乘
- 高精度(加减乘)改
- 高精度计算(高精度乘高精度,高精度减高精度)
- 高精度乘高精度FFT优化算法
- [复习]高精度 高精度加/减/乘/除法
- 高精度乘单精度 poj1001
- javascript流程控制、循环控制
- CPU/内存/缓存行/Disruptor
- servlet_05 servlet使用表单的GET方法实例
- java多线程总结
- Leetcode 257. Binary Tree Paths
- Light OJ 1024(高精度乘)
- Eclipse4.3 swt 插件在线安装
- 小程序-编辑器插件
- C语言再学习-- readelf、objdump、nm使用详解
- HMC(Hamiltonian Monte Carlo抽样算法详细介绍)
- hdu1401 Solitaire双向bfs
- 从存在的价值到人与机器的价值观
- 图形学笔记:图形管线
- 远程实习-第二周学习报告