现在的位置: 首页 > 例题 > 正文

整数的因式分解

2011年03月14日 例题 ⁄ 共 160字 ⁄ 字号 暂无评论

将任意整数进行因式分解,如:12=2*2*3,输出格式见示例

样例输入

60

样例输出

2
2
3
5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void f(int n)
{
	int i;
	for(i=2; i<n/2; i++) {
		while (n%i==0) {
			printf("%dn",i);
			n = n / i;
		}
	}
	if (n>1)
		printf("%dn", n);
}
 
#include <stdio.h>
 
int main(int argc, char *argv[])
{
	int n;
 
	scanf("%d", &n);
	f(n);
 
	return 0;
}

抱歉!评论已关闭.