- 注册时间
- 2007-12-27
- 最后登录
- 1970-1-1
- 威望
- 星
- 金币
- 枚
- 贡献
- 分
- 经验
- 点
- 鲜花
- 朵
- 魅力
- 点
- 上传
- 次
- 下载
- 次
- 积分
- 40348
- 在线时间
- 小时
|
发表于 2010-1-15 09:59:35
|
显示全部楼层
试着用LiLDA求解,发现代码有bug,做因子分解时经常崩溃掉,而且稍微添加一点代码,崩溃的地方都不同,不知道什么原因-
- #include <time.h>
- #include <LiDIA/rational_factorization.h>
- #include <iostream.h>
- using namespace LiDIA;
- using namespace std;
- #include <math.h>
- #define L 40
- #define N 8
- #define K 6
- unsigned long n[K];
- bigint M[K];
- bigint R[K];
- bigint maxM;
- int A[4];
- long long c;
- long long gc[L];
- int start_time;
-
- #define MAX_INDEX 20
- int iindex[MAX_INDEX];
- void solve()
- {
- bigint V,MM,RR,uu;
- MM=M[K-1];
- RR=R[K-1];
- V=MM*MM+RR;
- rational_factorization f;
- f.assign(V);
- f.factor();
- if(!f.is_prime_factorization()){
- printf("cannot factor %lld solution\n",c);
- }else{
- if(f.no_of_comp()>=MAX_INDEX){
- printf("too much compondents for %lld solution\n",c);
- }else{
- int i;
- for(i=0;i<f.no_of_comp();i++){
- iindex[i]=0;
- }
- do{
- bigint v=1;
- for(i=0;i<f.no_of_comp();i++){
- int j;
- for(j=0;j<iindex[i];j++){
- v*=f.base(i);
- }
- }
- if((v+MM)%RR==0){///solution found
- for(i=0;i<K;i++){
- cout<<"n"<<i+1<<"="<<n[i]<<";";
- }
- cout<<"n"<<K+1<<'='<<(v+MM)/RR<<";n"<<K+2<<"="<<(V/v+MM)/RR<<";\n";
- }
- for(i=f.no_of_comp()-1;i>=0;i--){
- if(iindex[i]==f.exponent(i)){
- iindex[i]=0;
- continue;
- }else{
- iindex[i]++;
- break;
- }
- }
- if(i<0)break;
- }while(1);
- }
- }
- fflush(stdout);
- }
-
- void output(int level, int overflow)
- {
- if(level==K){
- solve();
- }
- if(M[level-1]>maxM)maxM=M[level-1];
- c++;
- fprintf(stderr,"processed %lld by %ds\n",c,time(NULL)-start_time);
- }
-
- void search(int level)
- {
- if(level>=K){
- output(level,0);
- return;
- }
- double ll=(double)dbl(M[level-1])/dbl(R[level-1]);
- double uu=ll*(N-level);
- if(uu>=4294967295.5){///overflow
- output(level,1);
- return;
- }
- unsigned long li=(unsigned long)ceil(ll);
- unsigned long ui=(unsigned long)uu;
- if(li<=n[level-1])li=n[level-1]+1;
- unsigned long i;
- for(i=li;i<=ui;i++){
- if(gcd(M[level-1],i)!=1)
- continue;
- n[level]=i;
- M[level]=M[level-1]*i;
- R[level]=R[level-1]*i-M[level-1];
- A[i%4]++;
- search(level+1);
- A[i%4]--;
- }
- }
-
- void search0()
- {
- int i;
- for(i=0;i<4;i++)A[i]=0;
- for(i=2;i<=7;i++){
- n[0]=i;
- R[0]=i-1;
- M[0]=i;
- A[i%4]++;
- search(1);
- A[i%4]--;
- }
- }
-
- int main()
- {
- start_time=time(NULL);
- search0();
- int i;
- return 0;
- }
-
复制代码 |
|