- 注册时间
- 2007-12-27
- 最后登录
- 1970-1-1
- 威望
- 星
- 金币
- 枚
- 贡献
- 分
- 经验
- 点
- 鲜花
- 朵
- 魅力
- 点
- 上传
- 次
- 下载
- 次
- 积分
- 40149
- 在线时间
- 小时
|
发表于 2008-3-10 16:59:14
|
显示全部楼层
27应该对应模式应该是63个,而不是64个,上面写错了,下面代码可以打印出所有这些模式:- // flter.cpp : Defines the entry point for the console application.
- //
-
- #include "stdafx.h"
- #define OUTPUT
-
- int mask[]={1,1,2,6,12,60,60,420,840,2520,2520,27720,27720,360360,360360,360360,720720};
- int cands[]={17,19,23,29,31,37,41,43,47,53,59,61};
- int c2[]={5,7};
- int c3[]={1,2,4,5,6,7,2};
- #define NUMOF(x) (sizeof(x)/sizeof(x[0]))
- int _tmain(int argc, _TCHAR* argv[])
- {
- int i,j;
- for(i=0;i<NUMOF(cands);i++){
- int p=cands[i];
- int mt=256/p;
- int count=0;
- int lm=mask[mt];
- for(j=1;j<(1<<mt);j++){
- int sum=0;
- int k;
- for(k=0;k<mt;k++){
- if(j&(1<<k)){
- sum+=lm/(k+1);
- sum%=p;
- }
- }
- if(sum==0){
- int start=1;
- count++;
- #ifdef OUTPUT
- for(k=0;k<mt;k++){
- if(j&(1<<k)){
- if(!start)fprintf(stderr,"+");
- fprintf(stderr,"1/%d",(k+1)*p);
- start=0;
- }
- }
- fprintf(stderr,"\n");
- #endif
- }
- }
- printf("Count %d for prime %d\n",count,p);
- }
-
- for(i=0;i<NUMOF(c2);i++){
- int p=c2[i];
- int p2=p*p;
- int count=0;
- int mt=256/p2;
- int lm=mask[mt];
- for(j=1;j<(1<<mt);j++){
- int sum=0;
- int k;
- for(k=0;k<mt;k++){
- if(j&(1<<k)){
- sum+=lm/(k+1);
- sum%=p;
- }
- }
- if(sum==0){
- int start=1;
- count++;
- #ifdef OUTPUT
- for(k=0;k<mt;k++){
- if(j&(1<<k)){
- if(!start)fprintf(stderr,"+");
- fprintf(stderr,"1/%d",(k+1)*p2);
- start=0;
- }
- }
- fprintf(stderr,"\n");
- #endif
- }
- }
- printf("Count %d for %d\n",count,p2);
- }
-
- {
- int p=3;
- int p3=27;
- int mt=7;
- int count=0;
- int lm=mask[mt];
- for(j=1;j<(1<<mt);j++){
- int sum=0;
- int k;
- for(k=0;k<mt;k++){
- if(j&(1<<k)){
- sum+=lm/c3[k];
- sum%=p;
- }
- }
- if(sum==0){
- int start=1;
- count++;
- #ifdef OUTPUT
- for(k=0;k<mt;k++){
- if(j&(1<<k)){
- if(!start)fprintf(stderr,"+");
- if(k==mt-1){
- fprintf(stderr,"1/81+1/162");
- }else{
- fprintf(stderr,"1/%d",c3[k]*p3);
- }
- start=0;
- }
- }
- fprintf(stderr,"\n");
- #endif
- }
- }
- printf("Count %d for 27\n",count);
- lm = 1*3*5*7;
- count=0;
- for(j=1;j<16;j++){
- int sum=0;
- int k;
- for(k=0;k<4;k++){
- if(j&(1<<k)){
- sum+=lm/(2*k+1);
- sum%=2;
- }
- }
- if(sum==0){
- int start=1;
- count++;
- #ifdef OUTPUT
- for(k=0;k<4;k++){
- if(j&(1<<k)){
- if(!start)fprintf(stderr,"+");
- fprintf(stderr,"1/%d",(2*k+1)*32);
- start=0;
- }
- }
- fprintf(stderr,"\n");
- #endif
- }
- }
- printf("Count %d for 32\n",count);
- }
- return 0;
- }
复制代码 我们首先需要将它们转化为我上面说明的结构。 |
|