码迷,mamicode.com
首页 > 其他好文 > 详细

分拆素数和

时间:2017-05-02 22:12:25      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:miss   div   inpu   sqrt   std   problem   other   rip   scan   

 

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 25897    Accepted Submission(s): 11321


Problem Description

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

 


Input

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

 


Output

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

 


Sample Input

30 26 0

 


Sample Output

3 2

 

#include<stdio.h>
#include<math.h>
int f(int x)
{
 int i;
 for(i=2;i<=sqrt(x);i++)
 if(x%i==0)
 return 0;
 return 1;
}
main()
{
 int a,b,i,l,n,m;
 while(scanf("%d",&n)&&n!=0)
 {
    l=0;
 for(i=2;i<n-i;i++)
 if(f(i)&&f(n-i))
 l++;
 printf("%d\n",l);
    }
 return 0;
}

分拆素数和

标签:miss   div   inpu   sqrt   std   problem   other   rip   scan   

原文地址:http://www.cnblogs.com/ljbguanli/p/6798551.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!