验证:2000以内胡正偶数都能够分解为两个素数之和。
- #include <stdio.h>
- #include <math.h>
- int myflag(int i);
- int main(int argc, char *argv[])
- {
- int i, n;
- for(i=4; i<=2000; i +=2){
- for(n=2; n<i; n++){
- if(myflag(n)){
- if(myflag(i - n)){
- printf("%d = %d + %d\n", i, n, i-n);
- break;
- }
- }
- }
- if(n == i)
- printf("error %d\n", i);
- }
- return 0;
- }
- int myflag(int i)
- {
- int j;
- if(i <= 1)
- return 0;
- if(i == 2)
- return 1;
- if(!(i%2))
- return 0;
- for(j=3;j<=(int)(sqrt((double)i) + 1); j+=2)
- if(!(i%j))
- return 0;
- return 1;
- }
执行结果:
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
阅读(4012) | 评论(0) | 转发(0) |