算法提高 8-1因式分解 时间限制:10.0s 内存限制:256.0MB 提交此题 问题描述 设计算法,用户输入合数,程序输出若个素数的乘积。例如,输入6,输出2*3。输入20,输出2*2*5。 样例 与上面的样例输入对应的输出。 例:
数据规模和约定 输入数据中每一个数在int表示范围内。
#include<cstdio>#include <iostream>using namespace std;int main(){ int n; scanf("%d",&n); int x = 1; bool flag = true; while(n != 1) { x++; while(n % x == 0) { n /= x; if(flag) { flag = false; PRintf("%d",x); } else { printf("*%d",x); } } } return 0;}新闻热点
疑难解答