1717求素因子

求素因子

Time Limit: 1 Seconds     Memory Limit: 32768 K

Total Submit:589     Accepted:327


Description

任一整数x,找出它的素因子并以如下格式输出:
72=2*2*2*3*3
120=2*2*2*3*5

Input

任意整数x (-2100000000<x<2100000000)

Output

按照上述格式输出它的素因子(并换行回车)

Sample Input

-120

 

Sample Output

-120=-2*2*2*3*5

 

Source:

#include<iostream.h>
#include<cmath>
int main()
{
	int x,w;
	w=0;
	cin>>x;
	if(x<0)
	{
		w=1;
		x=-x;
	}
	long i,k=sqrt(x);
	i=2;
	if(w==1)
		cout<<"-"<<x<<"=-";
	else
		cout<<x<<"=";
	while(i<=k)
	{
		if(x%i==0)
		{
			cout<<i<<"*";
			x/=i;
			k=sqrt(x);
			continue;
		}
		i++;
	}
	cout<<x<<endl;
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值