• 博客访问： 2516813
• 博文数量： 308
• 博客积分： 5547
• 博客等级： 大校
• 技术积分： 3782
• 用 户 组： 普通用户
• 注册时间： 2009-11-24 09:47

hello world.

2012-07-07 11:18:33

验证：2000以内胡正偶数都能够分解为两个素数之和。

1. #include <stdio.h>
2. #include <math.h>

3. int myflag(int i);
4. int main(int argc, char *argv[])
5. {
6.   int i, n;
7.   for(i=4; i<=2000; i +=2){
8.     for(n=2; n<i; n++){
9.       if(myflag(n)){
10.         if(myflag(i - n)){
11.           printf("%d = %d + %d\n", i, n, i-n);
12.           break;
13.         }
14.       }
15.     }
16.     if(n == i)
17.       printf("error %d\n", i);
18.   }

19.   return 0;
20. }

21. int myflag(int i)
22. {
23.   int j;
24.   if(i <= 1)
25.     return 0;
26.   if(i == 2)
27.     return 1;
28.   if(!(i%2))
29.     return 0;

30.   for(j=3;j<=(int)(sqrt((double)i) + 1); j+=2)
31.     if(!(i%j))
32.       return 0;
33.   return 1;
34. }

31.c -lm
./a.out
1914 = 7 + 1907
1916 = 3 + 1913
1918 = 5 + 1913
1920 = 7 + 1913
1922 = 43 + 1879
1924 = 11 + 1913
1926 = 13 + 1913
1928 = 61 + 1867
1930 = 17 + 1913
1932 = 19 + 1913
1934 = 3 + 1931
1936 = 3 + 1933
1938 = 5 + 1933
1940 = 7 + 1933
1942 = 11 + 1931
1944 = 11 + 1933
1946 = 13 + 1933
1948 = 17 + 1931
1950 = 17 + 1933
1952 = 3 + 1949
1954 = 3 + 1951
1956 = 5 + 1951
1958 = 7 + 1951
1960 = 11 + 1949
1962 = 11 + 1951
1964 = 13 + 1951
1966 = 17 + 1949
1968 = 17 + 1951
1970 = 19 + 1951
1972 = 23 + 1949
1974 = 23 + 1951
1976 = 3 + 1973
1978 = 5 + 1973
1980 = 7 + 1973
1982 = 3 + 1979
1984 = 5 + 1979
1986 = 7 + 1979
1988 = 37 + 1951
1990 = 3 + 1987
1992 = 5 + 1987
1994 = 7 + 1987
1996 = 3 + 1993
1998 = 5 + 1993
2000 = 3 + 1997

0