频道栏目
首页 > 资讯 > 其他 > 正文

分拆素数和

17-08-18        来源:[db:作者]  
收藏   我要投稿

分拆素数和

Problem Description

把一个偶数拆成两个不同素数的和,有几种拆法呢?

Input

输入包含一些正的偶数,其值不会超过10000,个数不会超过500,若遇0,则结束。

Output

对应每个偶数,输出其拆成不同素数的个数,每个结果占一行。

Sample Input

30 26 0

Sample Output

3 2

#include
using namespace std;
#include
#include

bool sushu(int x)
{
	for (int i = 2; i <=sqrt( x+0.0) ; i++)
	{
		if (x%i == 0)
			return false;
	}
	return true;
}
int main()
{
	int n;
	while (cin >> n,n)
	{
		int num = 0;
		for (int i = 2; i < n / 2; i++)
		{
			if (sushu(i) && sushu(n - i))
			{
				num++;
			}
		}
		cout << num << endl;
	}
	return 0;
}
相关TAG标签
上一篇:【MySQL集群】——在Windows环境下配置MySQL集群
下一篇:提高 Java 代码性能的各种技巧
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站