1059 Prime Factors (25 分) 合数的因式分解( Composite number)

在这里插入图片描述

Input Specification:

Each input file contains one test case which gives a positive integer N in the range of long int.

Output Specification:

在这里插入图片描述

Sample Input:

97532468

Sample Output:

97532468=2^211171011291

Note

  1. 题意分解成因式,从小到大排列
  2. 注意质数 即 素数 prime

Code

#include<iostream>
#include<cmath>
using namespace std;
struct node{
    int base;
    int time;
}output[10001000];
int main(){
    long long input;
    long long cnt = 0;
    cin >> input;
	long long temp = input;
    long long i = 2;
    while(input > 1){
        int flag = 0;
        while(input % i == 0){
            input /= i;
            if(flag == 0){
                flag = 1;
                output[cnt].time = 1;
				output[cnt].base = i;
            }else
                output[cnt].time++;
        }
        if(flag == 1) cnt++;
        i++;
    }
    cout << temp << "=";
    if(input == temp){ cout << temp; return 0;}
    for(int i = 0; i < cnt; i++){
        if(output[i].time > 1) cout << output[i].base << "^" << output[i].time;
        else cout << output[i].base;
        if(i < cnt -1 )cout << "*";
    }
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值