算法提高 8-1因式分解

来源:互联网 发布:linux 串口调试助手 编辑:程序博客网 时间:2024/05/29 13:22

算法提高 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;}
1 0
原创粉丝点击