Counting Factor Trees zoj 3405
来源:互联网 发布:华为畅享5s手机壳淘宝 编辑:程序博客网 时间:2024/06/05 09:23
Time Limit: 2 Seconds Memory Limit: 65536 KB
Factoring, i.e., listing all the prime factors, of an integer is a useful skill that often helps to solve math problems. For example, one of the ways to find the GCD (Greatest Common Divisor) or LCM (Least Common Multiple) of two integers is by listing all their prime factors. The GCD is then the product of all the common factors; the LCM is the product of all the remaining ones.
The Factor Tree is a tool for finding such prime factorizations. The figure below demonstrates three factor trees of 108. At the beginning a root with a number is given, say N, which is to be factored. Then, the root is factored into two children N1 and N2 such that N = N1 × N2 (N1 ≥ 2, N2 ≥ 2). Note that N1 and N2 need not be prime. The same factoring process continues until all the leaves are prime.
While the prime factorization is unique, the factor tree reflects the order in which the factors were found, and is by no means unique. So, how many factor trees of a number are there?
Input
There are no more than 10000 cases. A line containing an integer N (2 ≤ N ≤ 1000000000) is given for each case.
Output
Print the number of factor trees of N in a line for each case. The answer will be fit in a signed 64-bit integer.
Sample Input
12108642485760
Sample Output
61409637611984000
Author: GAO, Yuan
Contest: ZOJ Monthly, September 2010
好悲剧!比赛时候没做出来,赛后CE,TLE过也就算了,还给我来过Floating Point Error (由于prime[i]算的不够多导致x除0!!!)
TLE的注意一下Method函数,也就是求x个元素有多少中排列方法的函数:
原来写成了
int Method(int num)
{
if(a[num])
return a[num];
int i,j;
int temp=0;
for(i=1;i<=num/2;i++)
{
temp+=Method(i)*Method(num-i)*2;
}
if(num%2==0)
temp-=Method(num/2)*Method(num/2);
return temp;
}
= =!
这样 temp-=Method(num/2)*Method(num/2); 岂不是要再算一遍!!
- Counting Factor Trees zoj 3405
- ZOJ Problem Set - 3405 Counting Factor Trees
- zoj 4013 Counting Factor Trees
- (zju3405)Counting Factor Trees
- zoj 3518 Unsafe Factor
- ZOJ 3518 Unsafe Factor
- HDU 3240 Counting Binary Trees
- zoj 1788 Quad Trees
- zoj 1788 Quad Trees
- zoj 1788 Quad Trees
- zoj 1629 Counting Triangles
- ZOJ Very Simple Counting
- zoj 1629 - Counting Triangles
- zoj 1629 Counting Triangles
- ZOJ 3944People Counting
- zoj 3944 People Counting
- zoj-3944-People Counting
- ZOJ-3944 People Counting
- 修改XML文件
- 《iPhone & iPad 开发实战》已由海洋出版社出版
- 获得document的iframe时有两种方法
- 获取浏览器和操作系统信息
- Java事件处理机制
- Counting Factor Trees zoj 3405
- fedora 9 安装VM tools
- 单一职责______开放封闭原则____依赖倒转”原则(DIP)
- Oracle 碎片整理
- Need call beginScene before rendering
- 设置path环境变量
- const
- Java实现视频播放功能
- WSS2010---给FEATURE添加Event Handle