HDOJ-1164-Eddy's research I 解题报告
2015-02-17 19:14
281 查看
分解质因数水题。题意:所有数都能够被分解成质因数的乘积,现在给你一个数,请输出这个数的质因数分解式。
我的解题思路:就是分解质因数,只是格式不太好处理而已。除了第一个质因数前面不要输出*,其他质因数前面都输出一个*就可以了。
我的解题代码:
我的解题思路:就是分解质因数,只是格式不太好处理而已。除了第一个质因数前面不要输出*,其他质因数前面都输出一个*就可以了。
我的解题代码:
#include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cmath> #include <climits> #include <algorithm> using namespace std; int num; void Factor(int x); int main() { while (~scanf("%d", &num)) { Factor(num); } return 0; } void Factor(int x) { int cnt = (int)sqrt(x + 0.5) + 1; bool isfirst = true; for (int i=2; i<cnt; ++i) { if (x % i == 0) { if (isfirst) { printf("%d", i); x /= i; isfirst = false; } while (x % i == 0) { printf("*%d", i); x /= i; } } } if (x > 1) { if (isfirst) { printf("%d", x); } else { printf("*%d", x); } } putchar('\n'); return; }
相关文章推荐
- hdoj-1164-Eddy's research I【分解质因数】
- HDOJ 1164 Eddy's research I
- 【hdoj 1164】Eddy's research I
- hdoj-1164-Eddy's research I【分解质因数】
- 杭电 HDU 1164 Eddy's research I
- hdu 1164 Eddy's research I
- HDU 1164 Eddy's research I
- HDU 1164 Eddy's research I 数论
- hdu 1164 Eddy's research I
- HDU1164 Eddy's research I
- HDU 1164 Eddy's research I
- HDOJ-1397-Goldbach's Conjecture 解题报告
- HDU 1164 Eddy's research I
- HDOJ-1160-FatMouse's Speed 解题报告
- hdu(1164)Eddy's research I
- HDOJ 1164 Eddy's research I(拆分成素数因子)
- 杭电OJ——1164 Eddy's research I——素数筛选
- hdu 1164 Eddy's research I (数论)
- HDOJ_1160:FatMouse's Speed 解题报告
- HDU1164_Eddy's research I【Miller Rabin素数测试】【Pollar Rho整数分解】