整数因子分解问题
2015-11-10 16:58
274 查看
整数因子分解问题
时间限制(普通/Java) : 1000 MS/ 3000 MS 运行内存限制 : 65536 KByte总提交 : 103 测试通过 : 46
比赛描述
大于1 的正整数n可以分解为:n=x1*x2*…*xm。
例如,当n=12 时,共有8 种不同的分解式:
12=12;
12=6*2;
12=4*3;
12=3*4;
12=3*2*2;
12=2*6;
12=2*3*2;
12=2*2*3。
对于给定的正整数n,编程计算n共有多少种不同的分解式。
输入
输入的第一行有1个正整数n (1≤n≤2000000000)。
输出
输出计算出的不同的分解式数。
样例输入
12
样例输出
8
递归解法:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int total; void solve(int n) { if(n == 1) { total++; return ; } int i; for(i = 2; i <= n; i++) { if(n % i == 0) { solve(n / i); } } } int main() { int n; while(~scanf("%d", &n)) { total = 0; solve(n); printf("%d\n", total); } return 0; }
相关文章推荐
- 转: iOS崩溃堆栈符号表使用与用途
- PHP Redis
- [big data 1] Hadoop 2 .x 伪分布搭建
- HDU_4123 && POJ_4003 Bob’s Race (dfs / bfs + RMQ + 尺取)
- iOS标准时间与时间戳相互转换
- Asp.net或C#使用word模板生成替换后的Word和pdf文档-总结
- UITextView解析
- linux使用FIO测试磁盘的iops
- hdu 1423 Greatest Common Increasing Subsequence(最长公共递增子序列LICS)
- Java中常用字符串方法总结
- document.frames与window.frames在不同浏览器中的使用
- jQuery代码开发技巧收集,jquery常用的开发代码
- IOS Core Image之一
- 空格的两个ascii值
- 杭电1420 Prepared for New Acmer
- awk
- 欢迎使用CSDN-markdown编辑器
- 移动APP的基本框架
- 【MongoDB for Java】Java操作MongoDB
- 黑马程序员——IO流