偶数分解成质数c语言,C++将偶数分解为质数

我创建了一个程序,可以将给定的偶数分解为两个素数之和。C++将偶数分解为质数

#include

#include

using namespace std;

int i(int x, int y)

{

if (x > y)

{

if (x % y)

return i(x, y + 1);

else

return 0;

}

else

return (x > 1);

}

int main()

{

int a, b;

do

{

cout << "Please input a positive even number: ";

cin >> a;

if (a % 2 == 0 && a >= 1)

{

for (b = a/2; b > 1; b--)

{

if ((i(b, 2) && i(a-b, 2)) &&

printf("%i + %i\n", b, a-b));

}

}

else if (a % 2 != 0 && a >= 1)

{

cout << a << "="<< a << endl;

}

else

break;

}

while(a >= 4);

return 0;

}

不过,我想打破偶数为一个素因子相乘首要因素,例如,12 = 2 * 2 * 3。修改程序的任何提示?感谢您的帮助

2014-12-03

Amy

+2

https://www.google.com/search?q=prime+factorization+c%2B%2B –

2014-12-03 14:18:15

+2

您所提供的代码中有共同的几乎没有与你的目标。你所要求的是所谓的分解,并且是无止境的重新审视。四处挖掘,并提出更具体的问题。 –

2014-12-03 14:23:01

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值