Permalink
Show file tree
Hide file tree
1 comment
on commit
sign in to comment.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
50 changed files
with
10,197 additions
and
0 deletions.
There are no files selected for viewing
180
code/A2.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
|
||
#include <list> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <stdlib.h> | ||
|
||
#define basemin 2 | ||
#define basemax 64 | ||
#define detail 25 | ||
#define wide 25000 | ||
|
||
using namespace std; | ||
|
||
char tr[128]; int w[128]; | ||
struct elem{unsigned long int n; | ||
list<short int> t; | ||
list <list<short int>::iterator> ptr; | ||
list<short int> next; | ||
}; | ||
struct node{list <short int> nexti; | ||
list <short int> l; list <list<node>::iterator> nextn; | ||
list <list<short int>::iterator> ptr; | ||
unsigned long int nblink, id; | ||
long int modmm1, modlmm1, gcd, gcdl, gcdf, dist; | ||
bool infty,final; | ||
}; | ||
ofstream kern,P; | ||
|
||
void printelem(elem el) | ||
{list<short int>::iterator iti; short int si; | ||
list <list<short int>::iterator>::iterator ititi; | ||
P<<'"';kern<<'"'; | ||
for (iti=el.t.begin();iti!=el.t.end();++iti) | ||
{si=*iti ; P<<tr[si];kern<<tr[si];} | ||
P<<'"'<<"="<<el.n;kern<<'"'<<"="<<el.n; | ||
P<<",\n";kern<<",\n";P.flush();kern.flush();} | ||
|
||
void printelemf(elem el) | ||
{list<short int>::iterator iti; short int si; | ||
list <list<short int>::iterator>::iterator ititi; | ||
P<<'"'; | ||
for (iti=el.t.begin();iti!=el.t.end();++iti) | ||
{si=*iti ; P<<tr[si];} | ||
P<<'"'<<"="<<el.n<<" : "; | ||
for (ititi=el.ptr.begin();ititi!=el.ptr.end();++ititi) | ||
{P<<tr[*(*ititi)]<<",";} P<<"->"; | ||
for (iti=el.next.begin();iti!=el.next.end();++iti) | ||
{si=*iti ; P<<tr[si];} | ||
P<<",\n";P.flush();} | ||
|
||
unsigned int pgcd(unsigned int i, unsigned int j) | ||
{unsigned int ii,jj,kk;if(i==0)return j; | ||
if(j>i){ii=j;jj=i;} else {ii=i;jj=j;} | ||
while(jj!=0){kk=ii%jj;ii=jj;jj=kk;} | ||
return ii;} | ||
unsigned int min(unsigned int i, unsigned int j) | ||
{if(i<=j)return i;else return j;} | ||
unsigned int max(unsigned int i, unsigned int j) | ||
{if(i<=j)return j;else return i;} | ||
bool ok(long int n) // is prime? | ||
{unsigned int kk; | ||
// if (n<2) return false; | ||
for (kk=2;kk*kk<=n;kk++) | ||
{if(n % kk==0)return false;} | ||
return true; | ||
} | ||
|
||
short int si,f,i,j,iinit; | ||
unsigned int m,g,gg,t1,ll,kk; | ||
unsigned long int ni,n,nmax,nn,szm,nn0,fact; | ||
bool test,modif; | ||
int cpustarttime; double cputime;int cpustarttime1; double cputime1;int cpustarttime2; double cputime2; | ||
unsigned int n0,n1,n2,n3,n4,n5; | ||
elem el,el1,el2,elmax; | ||
list<elem> todo, found; | ||
node auto0,auto1,auto2; | ||
list<node>autom; list<list<node>::iterator>nodetodo; | ||
list<elem>::iterator ite,ite1,ite2; | ||
list<node>::iterator itn,itn0,itn1,itn2; | ||
list<node>::reverse_iterator ritn,ritn0,ritn1,ritn2; | ||
list<short int>::iterator iti,iti1,iti2; | ||
list<list<short int>::iterator>::iterator ite3,ite4; | ||
list<list<node>::iterator>::iterator itepn,itepn1; | ||
list<list<node>::iterator>::iterator ittd; | ||
|
||
void handlebase(unsigned int m) | ||
{ | ||
cpustarttime=clock(); | ||
nmax=0;nn=m-1;n0=0; | ||
todo.clear(); found.clear(); | ||
|
||
P<<"\nbase="<<m<<":\n"; | ||
el.n=1; el.t.clear();el.t.push_back(1);el.ptr.clear();el.next.clear(); | ||
todo.push_back(el);fact=1; | ||
for (i=2;i<m;i++) | ||
{el.n=i; el.t.clear();el.t.push_back(i); el.ptr.clear();el.next.clear(); | ||
if (ok(i)) {found.push_back(el);printelem(el);fact=fact*i;} | ||
else{todo.push_back(el);}} | ||
for (ite1=todo.begin();ite1!=todo.end();++ite1) | ||
{(*ite1).next.push_back(0);(*ite1).next.push_back(1); | ||
for (i=2;i<m;i++){if(!ok(i)){(*ite1).next.push_back(i);}} | ||
for (ite2=found.begin();ite2!=found.end();++ite2) | ||
{(*ite1).ptr.push_back((*ite2).t.begin());} | ||
} | ||
// les structures sont initialisées, avec les chiffres de la base | ||
szm=todo.size(); | ||
while (!todo.empty()) // tant qu'il y a des todo | ||
{el=todo.front();ni=el.n; | ||
if(((((ni+1)*m)/m)!=(ni+1))// (ni>over) | ||
||(todo.size()>wide)){elmax=el;break;} // si trop long ou trop large: on arrête! | ||
else{todo.pop_front(); | ||
ite1=found.end();ite3=el.ptr.end();j=found.size()-el.ptr.size(); | ||
for (i=1;i<=j;i++) // s'il y a de nouveaux founds, on ajuste les structures | ||
{ite1--; iti1=(*ite1).t.begin();iti2=el.t.begin(); | ||
while(iti2!=el.t.end()){if((*iti1)==(*iti2)){iti1++;iti2++;}else{iti2++;}} | ||
ite3=el.ptr.insert(ite3,iti1); | ||
} | ||
for (iti=el.next.begin();iti!=el.next.end();iti++) // le préfixe considéré est allongé | ||
{el1=el;i=*iti;n=ni*m+i;el1.n=n;el1.t.push_back(i);nmax=n;ite1=found.begin(); nn++; | ||
for (ite3=el1.ptr.begin();ite3!=el1.ptr.end();ite3++) | ||
{if(i==(*(*ite3))){(*ite3)++; | ||
if((*ite3)==(*ite1).t.end())break;} | ||
ite1++; | ||
} | ||
if(ite3==el1.ptr.end()) | ||
{ // il n'est pas couvert | ||
if (ok(n)) | ||
{found.push_back(el1);printelem(el1);} // il est found | ||
else // il est todo, mais on ne le considère que si les allongements possibles ne certifient pas qu'ils seront composés | ||
{el1.next.clear();test=true; g=el1.n; // g est le gcd des allongements possibles | ||
for(iti1=el.next.begin();iti1!=el.next.end();iti1++) // un allongement est envisagé | ||
{j=*iti1;ite1=found.begin(); | ||
for (ite4=el1.ptr.begin();ite4!=el1.ptr.end();ite4++) | ||
{if(j==(*(*ite4))){iti2=*ite4;if((++iti2)==(*ite1).t.end()){break;}} | ||
ite1++; | ||
} | ||
if(ite4==el1.ptr.end()){el1.next.push_back(j); | ||
g=pgcd(g,j);test=test && (pgcd(j,m)!=1);}// il n'est pas couvert par la base | ||
} | ||
if((!test) and (g==1)) {todo.push_back(el1);} else{n0++;} | ||
//cputime1 = clock()-cpustarttime1; cputime1=cputime1/1000000;if(cputime1>0.001) | ||
} | ||
} | ||
if(todo.size()>szm)szm=todo.size(); | ||
} // fin de la boucle d'allongement | ||
}} // fin de la boucle sur todo | ||
|
||
cputime = clock()-cpustarttime; cputime=cputime/1000000;cpustarttime1=clock(); | ||
P<<"\nla taille de la base de nombres premiers est de : "<<found.size(); | ||
P<<"\nil a fallu "<<cputime<<" secondes pour les obtenir, considérer "<<nn<<" candidats, dont "<<szm<<" en même temps, et appliquer "<<n0<<" fois la règle d'élagage."; | ||
P<<"\nle plus grand entier traité est : "<<nmax; | ||
if(!todo.empty()){ | ||
P<<"\n_____________________________________________________"; | ||
P<<"\nil restait encore "<<todo.size()<<" préfixes à traiter\n"; | ||
P.flush(); | ||
if(false) | ||
{if(todo.size()<=2*detail){for (ite=todo.begin();ite!=todo.end();++ite) | ||
{el=*ite;printelemf(el);}} | ||
else {i=0; for (ite=todo.begin();i++<detail;++ite) | ||
{el=*ite;printelemf(el);}P<<".....\n";ite=todo.end(); | ||
i=0;for (ite--;i++<detail;ite--) | ||
{el=*ite;printelemf(el);}} | ||
P<<"\n===============================================\n";P.flush(); | ||
}} | ||
} | ||
int main(int argc, char *argv[]) | ||
{string ms,pref,prefms;int m,k; | ||
for(k=1;k<argc;k++) | ||
{ms=argv[k];m=atoi(argv[k]); | ||
pref="P"; prefms=pref+ms; | ||
P.open(prefms.c_str(),ios::out); | ||
pref="kernel"; prefms=pref+ms; | ||
kern.open(prefms.c_str(),ios::out); | ||
for(char c='0';c<='9';c++){w[c]=0+c-'0';tr[0+c-'0']=c;} | ||
for(char c='A';c<='Z';c++){w[c]=10+c-'A';tr[10+c-'A']=c;} | ||
for(char c='a';c<='z';c++){w[c]=36+c-'a';tr[36+c-'a']=c;} | ||
handlebase(m); | ||
P.close();kern.close();} | ||
} // fin main |
120
code/a1.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#include <string> | ||
#include <list> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#define wide 25000 | ||
|
||
using namespace std; | ||
|
||
struct elem{unsigned long int n; | ||
list<short int> t; | ||
list <list<short int>::iterator> ptr; | ||
list<short int> next; | ||
}; | ||
string tr; | ||
ofstream kern,P; | ||
|
||
void printelem(elem el) | ||
{list<short int>::iterator iti; short int si; | ||
list <list<short int>::iterator>::iterator ititi; | ||
P<<'"';kern<<'"'; | ||
for (iti=el.t.begin();iti!=el.t.end();++iti) | ||
{si=*iti ; P<<tr[si];kern<<tr[si];} | ||
P<<'"'<<"="<<el.n;kern<<'"'<<"="<<el.n; | ||
P<<",\n";kern<<",\n";P.flush();kern.flush();} | ||
|
||
unsigned int min(unsigned int i, unsigned int j) | ||
{if(i<=j)return i;else return j;} | ||
|
||
bool ok(long int n) // is prime? | ||
{unsigned int kk; | ||
// if (n<2) return false; | ||
for (kk=2;kk*kk<=n;kk++) | ||
{if(n % kk==0)return false;} | ||
return true; | ||
} | ||
|
||
short int si,f,i,j,iinit; | ||
unsigned int m,g,gg,t1,ll,kk; | ||
unsigned long int ni,n,nmax,nn,szm,nn0,fact; | ||
int cpustart; double cptime; | ||
elem el,el1; | ||
list<elem> todo, found; | ||
list<elem>::iterator ite,ite1,ite2; | ||
list<short int>::iterator iti,iti1,iti2; | ||
list<list<short int>::iterator>::iterator ite3,ite4; | ||
|
||
void handlebase(unsigned int m) | ||
{ | ||
cpustart=clock(); | ||
nmax=0;nn=m-1; | ||
todo.clear(); found.clear(); tr=""; | ||
for (i=0;i<min(m,10);i++)tr.push_back('0'+i); | ||
for (i=10;i<m;i++)tr.push_back('A'+i-10); | ||
|
||
P<<"\nbase="<<m<<":\n"; | ||
el.n=1; el.t.clear();el.t.push_back(1);el.ptr.clear();el.next.clear(); | ||
todo.push_back(el);fact=1; | ||
for (i=2;i<m;i++) | ||
{el.n=i; el.t.clear();el.t.push_back(i); el.ptr.clear();el.next.clear(); | ||
if (ok(i)) {found.push_back(el);printelem(el);fact=fact*i;} | ||
else{todo.push_back(el);}} | ||
for (ite1=todo.begin();ite1!=todo.end();++ite1) | ||
{(*ite1).next.push_back(0);(*ite1).next.push_back(1); | ||
for (i=2;i<m;i++){if(!ok(i)){(*ite1).next.push_back(i);}} | ||
for (ite2=found.begin();ite2!=found.end();++ite2) | ||
{(*ite1).ptr.push_back((*ite2).t.begin());} | ||
} | ||
// les structures sont initialisées, avec les chiffres de la base | ||
szm=todo.size(); | ||
while (!todo.empty()) // tant qu'il y a des todo | ||
{el=todo.front();ni=el.n; | ||
if(((((ni+1)*m)/m)!=(ni+1))// (ni>over) | ||
||(todo.size()>wide))break; // si trop long ou trop large: on arrête! | ||
else{todo.pop_front(); | ||
ite1=found.end();ite3=el.ptr.end();j=found.size()-el.ptr.size(); | ||
for (i=1;i<=j;i++) // s'il y a de nouveaux founds, on ajuste les structures | ||
{ite1--; iti1=(*ite1).t.begin();iti2=el.t.begin(); | ||
while(iti2!=el.t.end()){if((*iti1)==(*iti2)){iti1++;iti2++;}else{iti2++;}} | ||
ite3=el.ptr.insert(ite3,iti1); | ||
} | ||
for (iti=el.next.begin();iti!=el.next.end();iti++) // le préfixe considéré est allongé | ||
{el1=el;i=*iti;n=ni*m+i;el1.n=n;el1.t.push_back(i);nmax=n; | ||
ite1=found.begin(); nn++; | ||
for (ite3=el1.ptr.begin();ite3!=el1.ptr.end();ite3++) | ||
{if(i==(*(*ite3))){(*ite3)++; | ||
if((*ite3)==(*ite1).t.end())break;} | ||
ite1++; | ||
} | ||
if(ite3==el1.ptr.end()) | ||
{ // il n'est pas couvert | ||
if (ok(n)) | ||
{found.push_back(el1);printelem(el1);} // il est found | ||
else todo.push_back(el1); | ||
} | ||
if(todo.size()>szm)szm=todo.size(); | ||
} // fin de la boucle d'allongement | ||
}} // fin de la boucle sur todo | ||
// | ||
cptime = (clock()-cpustart)/1000000.0; | ||
P<<"\nla taille de la base de nombres premiers est de : "<<found.size(); | ||
P<<"\nil a fallu "<<cptime<<" secondes pour les obtenir, considérer "<<nn<<" candidats, dont "<<szm<<" en même temps."; | ||
P<<"\nle plus grand entier traité est : "<<nmax; | ||
if(!todo.empty()){ | ||
P<<"\n_____________________________________________________"; | ||
P<<"\nil restait encore "<<todo.size()<<" préfixes à traiter\n"; | ||
P<<"\n===============================================\n";P.flush(); | ||
} | ||
} | ||
int main(int argc, char *argv[]) | ||
{string ms,pref,prefms;int m,k; | ||
for(k=1;k<argc;k++) | ||
{ms=argv[k];m=atoi(argv[k]); | ||
pref="P"; prefms=pref+ms; | ||
P.open(prefms.c_str(),ios::out); | ||
pref="Kp"; prefms=pref+ms; | ||
kern.open(prefms.c_str(),ios::out); | ||
handlebase(m); | ||
P.close();kern.close();} | ||
} // fin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include <stdlib.h> | ||
using namespace std; | ||
|
||
struct elem{string mm, m10;}; | ||
list<elem> found; elem el; | ||
|
||
ifstream kern; ofstream ckern; | ||
bool cover(string el1,string el2) | ||
{int i,j,k; | ||
if(el1.length()==el2.length())return false; | ||
if(el1.length()>el2.length())return(false); | ||
i=0;j=0; | ||
while(i<el1.length()) | ||
{if(el1[i]==el2[j]) | ||
{i++;j++;if(i==el1.length())return true;if(j>=el2.length())return false;} | ||
else{j++;if(j>=el2.length())return false;} | ||
} | ||
return true; | ||
} | ||
int order(string el1,string el2) | ||
{int i; | ||
if(el1.length()>el2.length())return 1; | ||
if(el1.length()<el2.length())return 2; | ||
i=0; | ||
while(i<el1.length()) | ||
{if(el1[i]==el2[i])i++; | ||
else if(el1[i]<el2[i])return 2; | ||
else return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
main(int argc, char *argv[]) | ||
{string p,ms,pref,prefms,mm,m10,mM,md;int m,k,nn,l,i,j; | ||
bool fin; | ||
list<string> foundM,found10; | ||
list<elem>::iterator it,itp; | ||
for(k=1;k<argc;k++) | ||
{ms=argv[k];m=atoi(argv[k]); | ||
pref="kernel"; prefms=pref+ms; | ||
kern.open(prefms.c_str()); | ||
nn=0; | ||
while(kern>>p) | ||
{l=p.length(); | ||
if(p[0]!='"'){cerr<<"problème de quote à la ligne"<<p; } | ||
if(p[l-1]!=','){p=p+",";cerr<<"problème de , à la ligne"<<p; } | ||
for(i=1;i<l;i++)if(p[i]=='>') | ||
{p='"'+p.substr(i+1,l-1);l=p.length();break;} | ||
for(i=1;i<l;i++)if(p[i]=='"') | ||
{mm=p.substr(1,i-1);m10=p.substr(i+2,l-i-3);break;} | ||
el.mm=mm;el.m10=m10;found.push_back(el); | ||
}cerr<<"on demarre avec "<<found.size()<<" membres\n"; | ||
while(cin>>p) | ||
{nn++;if((nn%1000)==0)cerr<<ms<<":"<<p<<"("<<found.size()<<")\n"; | ||
l=p.length(); | ||
if(p[0]!='"'){cerr<<"problème de quote à la ligne"<<p; } | ||
if(p[l-1]!=','){p=p+",";cerr<<"problème de , à la ligne"<<p; } | ||
for(i=1;i<l;i++)if(p[i]=='>') | ||
{p='"'+p.substr(i+1,l-1);l=p.length();break;} | ||
for(i=1;i<l;i++)if(p[i]=='"') | ||
{mm=p.substr(1,i-1);m10=p.substr(i+2,l-i-3);break;} | ||
for(it=found.begin();it!=found.end();it++)if(cover((*it).mm,mm))break; | ||
if(it==found.end()) | ||
{it=found.begin();while(it!=found.end()) | ||
{if(cover(mm,(*it).mm))it=found.erase(it); else it++;} | ||
for(it=found.begin();it!=found.end();it++) | ||
{if(order(mm,(*it).mm)==0)break; | ||
if(order(mm,(*it).mm)==2) | ||
{el.mm=mm;el.m10=m10;found.insert(it,el);break;} | ||
} | ||
if(it==found.end()){el.mm=mm;el.m10=m10;found.push_back(el);} | ||
} | ||
}cerr<<"on termine avec "<<found.size()<<" membres\n"; | ||
for(it=found.begin();it!=found.end();it++) | ||
cout<<'"'<<(*it).mm<<'"'<<'='<<(*it).m10<<",\n"; | ||
kern.close(); | ||
}} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include <stdlib.h> | ||
using namespace std; | ||
|
||
struct elem{string mm, m10;}; | ||
list<elem> found; elem el; | ||
|
||
ifstream kern; ofstream ckern; | ||
bool cover(string el1,string el2) | ||
{int i,j,k; | ||
if(el1.length()==el2.length())return false; | ||
if(el1.length()>el2.length())return(false); | ||
i=0;j=0; | ||
while(i<el1.length()) | ||
{if(el1[i]==el2[j]) | ||
{i++;j++;if(i==el1.length())return true;if(j>=el2.length())return false;} | ||
else{j++;if(j>=el2.length())return false;} | ||
} | ||
return true; | ||
} | ||
int order(string el1,string el2) | ||
{int i; | ||
if(el1.length()>el2.length())return 1; | ||
if(el1.length()<el2.length())return 2; | ||
i=0; | ||
while(i<el1.length()) | ||
{if(el1[i]==el2[i])i++; | ||
else if(el1[i]<el2[i])return 2; | ||
else return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
main(int argc, char *argv[]) | ||
{string p,ms,pref,prefms,mm,m10,mM,md;int m,k,nn,l,i,j; | ||
bool fin; | ||
list<string> foundM,found10; | ||
list<elem>::iterator it,itp; | ||
for(k=1;k<argc;k++) | ||
{ms=argv[k];m=atoi(argv[k]); | ||
pref="kernel"; prefms=pref+ms; | ||
kern.open(prefms.c_str()); | ||
nn=0; | ||
while(kern>>p) | ||
{l=p.length(); | ||
if(p[0]!='"'){cerr<<"problème de quote à la ligne"<<p; } | ||
if(p[l-1]!=','){p=p+",";cerr<<"problème de , à la ligne"<<p; } | ||
for(i=1;i<l;i++)if(p[i]=='>') | ||
{p='"'+p.substr(i+1,l-1);l=p.length();break;} | ||
for(i=1;i<l;i++)if(p[i]=='"') | ||
{mm=p.substr(1,i-1);m10=p.substr(i+2,l-i-3);break;} | ||
el.mm=mm;el.m10=m10;found.push_back(el); | ||
}cerr<<"on demarre avec "<<found.size()<<" membres\n"; | ||
while(cin>>p) | ||
{nn++;if((nn%1000)==0)cerr<<ms<<":"<<p<<"("<<found.size()<<")\n"; | ||
l=p.length(); | ||
if(p[0]!='"'){cerr<<"problème de quote à la ligne"<<p; } | ||
if(p[l-1]!=','){p=p+",";cerr<<"problème de , à la ligne"<<p; } | ||
for(i=1;i<l;i++)if(p[i]=='>') | ||
{p='"'+p.substr(i+1,l-1);l=p.length();break;} | ||
for(i=1;i<l;i++)if(p[i]=='"') | ||
{mm=p.substr(1,i-1);m10=p.substr(i+2,l-i-3);break;} | ||
for(it=found.begin();it!=found.end();it++) | ||
{if((*it).mm.size()<mm.size()){if(cover((*it).mm,mm))break;}else break;} | ||
if(it==found.end()){el.mm=mm;el.m10=m10;found.push_back(el);continue;} | ||
if((*it).mm.size()<mm.size())continue; | ||
while((*it).mm.size()==mm.size()) | ||
{k=order(mm,(*it).mm); | ||
if(k==0)break; | ||
if(k==2) | ||
{el.mm=mm;el.m10=m10;found.insert(it,el); | ||
while((*it).mm.size()==mm.size())it++;break; | ||
} | ||
it++; | ||
} | ||
if(k==0)continue; | ||
if(k==1){el.mm=mm;el.m10=m10;found.insert(it,el);} | ||
while(it!=found.end()) | ||
{if(cover(mm,(*it).mm))it=found.erase(it); else it++;} | ||
}cerr<<"on termine avec "<<found.size()<<" membres\n"; | ||
for(it=found.begin();it!=found.end();it++) | ||
cout<<'"'<<(*it).mm<<'"'<<'='<<(*it).m10<<",\n"; | ||
kern.close(); | ||
}} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include <stdlib.h> | ||
using namespace std; | ||
|
||
struct elem{string mm, m10;}; | ||
list<elem> found; elem el; | ||
|
||
ifstream kern; ofstream ckern; | ||
bool cover(string el1,string el2) | ||
{int i,j,k; | ||
if(el1.length()>el2.length())return false; | ||
i=0;j=0; | ||
while(i<el1.length()) | ||
{if(el1[i]==el2[j]) | ||
{i++;j++;if(i==el1.length())return true;if(j>=el2.length())return false;} | ||
else{j++;if(j>=el2.length())return false;} | ||
} | ||
return true; | ||
} | ||
int order(string el1,string el2) | ||
{int i; | ||
if(el1.length()>el2.length())return 1; | ||
if(el1.length()<el2.length())return 2; | ||
i=0; | ||
while(i<el1.length()) | ||
{if(el1[i]==el2[i])i++; | ||
else if(el1[i]<el2[i])return 2; | ||
else return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
string itos(int i) // convert int to string | ||
{stringstream s;s << i;return s.str();} | ||
|
||
string cvrt(char c) | ||
{if((c>='0')&&(c<='9')) return itos(c-'0'); else return itos(10+c-'A');} | ||
|
||
main(int argc, char *argv[]) | ||
{string p,ms,pref,prefms,mm,m10,mM,md;int m,k,nn,l,i,j; | ||
bool fin; | ||
list<string> foundM,found10; | ||
list<elem>::iterator it,itp; | ||
for(k=1;k<argc;k++) | ||
{ms=argv[k];m=atoi(argv[k]); | ||
pref="kernel"; prefms=pref+ms; | ||
kern.open(prefms.c_str()); | ||
nn=0; | ||
while(kern>>p) | ||
{l=p.length(); | ||
if(p[0]!='"'){cout<<"problème de quote à la ligne"<<p; } | ||
if(p[l-1]!=','){p=p+",";cout<<"problème de , à la ligne"<<p; } | ||
for(i=1;i<l;i++)if(p[i]=='>') | ||
{p='"'+p.substr(i+1,l-1);l=p.length();break;} | ||
for(i=1;i<l;i++)if(p[i]=='"') | ||
{mm=p.substr(1,i-1);m10=p.substr(i+2,l-i-3);break;} | ||
el.mm=mm;el.m10=m10;found.push_back(el); | ||
} | ||
while(cin>>p) | ||
{nn++;if((nn%1000)==0)cerr<<ms<<":"<<p<<"("<<found.size()<<")\n"; | ||
l=p.length(); | ||
if(p[0]!='"'){cout<<"problème de quote à la ligne"<<p; } | ||
if(p[l-1]!=','){p=p+",";cout<<"problème de , à la ligne"<<p; } | ||
for(i=1;i<l;i++)if(p[i]=='>') | ||
{p='"'+p.substr(i+1,l-1);l=p.length();break;} | ||
for(i=1;i<l;i++)if(p[i]=='"') | ||
{mm=p.substr(1,i-1);m10=p.substr(i+2,l-i-3);break;} | ||
for(it=found.begin();it!=found.end();it++) | ||
if(cover((*it).mm,mm)){cerr<<mm<<" is covered by "<<(*it).mm<<"\n"; break;} | ||
if(it==found.end()) | ||
{it=found.begin();while(it!=found.end()) | ||
{if(cover(mm,(*it).mm))it=found.erase(it); else it++;} | ||
for(it=found.begin();it!=found.end();it++) | ||
{if(order(mm,(*it).mm)==0)break; | ||
if(order(mm,(*it).mm)==2) | ||
{el.mm=mm;el.m10=m10;found.insert(it,el);break;} | ||
} | ||
if(it==found.end()){el.mm=mm;el.m10=m10;found.push_back(el);} | ||
} | ||
} | ||
for(it=found.begin();it!=found.end();it++) | ||
cout<<'"'<<(*it).mm<<'"'<<'='<<(*it).m10<<",\n"; | ||
kern.close(); | ||
}} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include "big.h" /* include MIRACL system */ | ||
using namespace std; | ||
|
||
Miracl precision(20000,100); /* bigs are 10000 centimal digits long */ | ||
|
||
string s10(Big x) | ||
{Big y=x; Big br; int r; string s=""; char c; | ||
while (y!=0){br=y%10;y=y/10; | ||
if(br==0)r=0;if(br==1)r=1;if(br==2)r=2;if(br==3)r=3;if(br==4)r=4;if(br==5)r=5; | ||
if(br==6)r=6;if(br==7)r=7;if(br==8)r=8;if(br==9)r=9;c='0'+r;s=c+s;}return s; | ||
} | ||
ifstream result;int deploy,b;string p; | ||
char tr[128]; int w[128],k; | ||
Big nbd,MM ; | ||
string itos(int i) // convert int to string | ||
{stringstream s;s << i;return s.str();} | ||
|
||
string cvrt(char c) | ||
{if((c>='0')&&(c<='9')) return itos(c-'0'); else return itos(10+c-'A');} | ||
string sb(Big x) | ||
{Big y=x; Big br; int r; string s=""; char c; | ||
while (y!=0){br=y%b;y=y/b; | ||
for(r=0;r<36;r++)if(br==r)break; | ||
if(r<10)c='0'+r; else c='A'+r-10; s=c+s;}return s; | ||
} | ||
void printstringM(string s,string sr,int d) | ||
{int i,j,ki,kj,dd;string ll,ss;char c; | ||
for(i=0;i<sr.length();i++)if((sr[i]=='{')||(sr[i]=='<')){if((sr[i+1]=='}')||(sr[i+1]=='>'))i=i+2;else break;} else s=s+sr[i]; | ||
if(i<sr.length())sr=sr.substr(i,sr.length()-i+1);else sr=""; | ||
if(sr.empty()){nbd=0; for(j=0;j<s.length();j++)nbd=nbd*b+w[s[j]]; | ||
cout<<" "<<'"'<<p<<'"'<<"=>"<<'"'<<s<<'"'<<"= "<<s10(nbd)<<"\n";MM=nbd; | ||
if(nbd==0)cout<<"is 0\n"; else | ||
if(nbd==1)cout<<"is 1\n"; else | ||
if(prime(nbd))cout<<"is prime\n"; else | ||
{k=2;while(!prime(nbd)){while((nbd%k)!=0)if(k>100000)break; else k++; | ||
if(k<100000){cout<<sb(k)<<'('<<sb(MM/k)<<')'<<'.';nbd=nbd/k;cout.flush();} | ||
else break; } | ||
if(k<100000)cout<<sb(nbd)<<'('<<sb(MM/nbd)<<')'<<"\n";else cout<<"...\n";cout.flush(); | ||
} | ||
return; | ||
} | ||
ll="";for(i=1;i<sr.length();i++)if((sr[i]=='}')||(sr[i]=='>'))break;else ll=ll+sr[i]; | ||
ss=sr.substr(i+1,sr.length()-i);if(d==0)dd=0;else dd=(d-1)/ll.length();printstringM(s,ss,dd); | ||
if(d>0){for(ki=0;ki<ll.length();ki++){cerr<<'.';printstringM(s+ll[ki],sr,dd);}} | ||
} | ||
|
||
main(int argc, char *argv[]) | ||
{string ms,pref,prefms; | ||
deploy=atoi(argv[2]); | ||
ms=argv[1];b=atoi(argv[1]); | ||
for(char c='0';c<='9';c++){w[c]=0+c-'0';tr[0+c-'0']=c;} | ||
for(char c='A';c<='Z';c++){w[c]=10+c-'A';tr[10+c-'A']=c;} | ||
for(char c='a';c<='z';c++){w[c]=36+c-'a';tr[36+c-'a']=c;} | ||
while(cin>>p)if(p[0]=='%')break; | ||
else {cerr<<"\n"<<p;printstringM("",p,deploy);cout<<"\n===================================\n";} | ||
cerr<<"\n===================================\n"; | ||
} // fin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <stdlib.h> | ||
#include "big.h" /* include MIRACL system */ | ||
using namespace std; | ||
|
||
Miracl precision(20000,128); /* bigs are 10000 centimal digits long */ | ||
|
||
char tr[128]; int w[128]; | ||
|
||
|
||
string s10(Big x) | ||
{Big y=x; int r; string s=""; | ||
while (y!=0){r=y%10;y=y/10;s=tr[r]+s;} | ||
return s; | ||
} | ||
|
||
ifstream kern; | ||
bool cover(string el1,string el2) | ||
{int i,j,k; | ||
if(el1.length()==el2.length())return false; | ||
if(el1.length()>el2.length())return(false); | ||
i=0;j=0; | ||
while(i<el1.length()) | ||
{if(el1[i]==el2[j]) | ||
{i++;j++;if(i==el1.length())return true;if(j>=el2.length())return false;} | ||
else{j++;if(j>=el2.length())return false;} | ||
} | ||
return true; | ||
} | ||
main(int argc, char *argv[]) | ||
{string p,ms,pref,prefms,mm,m10; | ||
int m,k,nn,l,i,j; | ||
int w[128]; | ||
char c; | ||
Big nm,n10,on; | ||
list<string> foundM; | ||
list<string>::iterator itM; | ||
for(i=0;i<128;i++)w[i]=-1; | ||
for(char c='0';c<='9';c++){w[c]=0+c-'0';tr[0+c-'0']=c;} | ||
for(char c='A';c<='Z';c++){w[c]=10+c-'A';tr[10+c-'A']=c;} | ||
for(char c='a';c<='z';c++){w[c]=36+c-'a';tr[36+c-'a']=c;} | ||
for(k=1;k<argc;k++) | ||
{ms=argv[k];m=atoi(argv[k]); | ||
pref="kernel"; prefms=pref+ms; | ||
kern.open(prefms.c_str()); | ||
nn=0; | ||
cerr<<"\nTraitement de la base "<<m<<"\n"; | ||
while(kern>>p) | ||
{nn++;l=p.length();if((nn%1000)==0)cerr<<nn<<':'<<p<<"\n"; | ||
if(p[0]!='"'){cerr<<"problème de quote à la ligne "<<nn<<" = "+p;break; } | ||
if(p[l-1]!=','){cerr<<"problème de , à la ligne "<<nn<<" = "+p;break; } | ||
for(i=1;i<l;i++)if(p[i]=='"') | ||
{mm=p.substr(1,i-1);m10=p.substr(i+2,l-i-3);break;} | ||
if(i==l){cerr<<"problème de quote à la ligne "<<nn<<" = "+p;break; } | ||
if(p[i+1]!='='){cerr<<"problème de = à la ligne "<<nn<<" = "+p;break; } | ||
l=mm.length();nm=0; | ||
for(i=0;i<l;i++)if((w[mm[i]]==-1)||(w[mm[i]]>=m)) | ||
{cerr<<"problème de base à la ligne "<<nn<<" = "+p;break; } | ||
else{nm=nm*m+w[mm[i]];} | ||
l=m10.length();n10=0; | ||
for(i=0;i<l;i++)if((w[m10[i]]==-1)||(w[m10[i]]>=10)) | ||
{cerr<<"problème de base 10 à la ligne "<<nn<<" = "+p;break; } | ||
else{n10=n10*10+w[m10[i]];} | ||
if(!prime(nm)){cerr<<"problème de primalité à la ligne "<<nn<<" = "+p;break; } | ||
if(nm!=n10){cerr<<"problème d'égalité à la ligne "<<nn<<" = "+p;break; } | ||
if((nn>1)&&(on>nm)) | ||
{cerr<<"problème d'ordre à la ligne "<<nn<<" = "+p;break; } | ||
itM=foundM.begin();on=nm; | ||
while(itM!=foundM.end()) | ||
{if(cover(*itM,mm)){cerr<<"problème de dominance à la ligne "<<nn<<" = "+p<<" parrapport à "+*itM;break; } else itM++; | ||
}if(itM!=foundM.end())break; | ||
foundM.push_back(mm); | ||
} | ||
cerr<<"on s'arrête à la ligne "<<nn;foundM.clear();kern.close(); | ||
}} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <stdlib.h> | ||
#include "big.h" /* include MIRACL system */ | ||
using namespace std; | ||
|
||
Miracl precision(20000,128); /* bigs are 10000 centimal digits long */ | ||
|
||
char tr[128]; int w[128]; | ||
|
||
|
||
string s10(Big x) | ||
{Big y=x; int r; string s=""; | ||
while (y!=0){r=y%10;y=y/10;s=tr[r]+s;} | ||
return s; | ||
} | ||
|
||
main(int argc, char *argv[]) | ||
{string p,ms,mm,m10;int m,k,nn,l,i,j; | ||
char c; Big nm,n10; | ||
for(char c='0';c<='9';c++){w[c]=0+c-'0';tr[0+c-'0']=c;} | ||
for(char c='A';c<='Z';c++){w[c]=10+c-'A';tr[10+c-'A']=c;} | ||
for(char c='a';c<='z';c++){w[c]=36+c-'a';tr[36+c-'a']=c;} | ||
for(k=1;k<argc;k++) | ||
{ms=argv[k];m=atoi(argv[k]);nn=0; | ||
cerr<<"traitement de la base "<<ms<<"\n";cerr.flush(); | ||
while(cin>>p) | ||
{l=p.length();nn++; | ||
if(p[0]!='"')cerr<<"problème de quote à la ligne"<<nn; | ||
if(p[l-1]!=',')cerr<<"problème de , à la ligne"<<nn; | ||
for(i=1;i<l;i++)if(p[i]=='"') | ||
{mm=p.substr(1,i-1);m10=p.substr(i+2,l-i-3);break;} | ||
nm=0;for(i=0;i<mm.length();i++){c=mm[i];if((c>='0')&&(c<='9')){j=c-'0';} else if((c>='A')&&(c<='Z')){j=10+c-'A';} else {j=36+c-'a';} nm=nm*m+j;} | ||
n10=0;for(i=0;i<m10.length();i++){c=m10[i];if((c>='0')&&(c<='9'))j=c-'0'; else {cerr<<"problème 10\n";break;}n10=n10*10+j;} | ||
if(!prime(nm))cerr<<"problème de primalité :"<<mm<<"%"<<m10<<"|"<<s10(nm)<<"|"<<s10(n10)<<"\n"; else | ||
{if(nm!=n10)cerr<<"problème d'égalité :"<<mm<<"%"<<m10<<"|"<<s10(nm)<<"|"<<s10(n10)<<"\n"; else | ||
cout<<p<<"\n";} | ||
}}} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include "big.h" /* include MIRACL system */ | ||
using namespace std; | ||
|
||
Miracl precision(20000,128); /* bigs are 10000 centimal digits long */ | ||
|
||
char tr[128]; int w[128]; | ||
|
||
string s10(Big x) | ||
{Big y=x; int r; string s=""; | ||
while (y!=0){r=y%10;y=y/10;s=tr[r]+s;} | ||
return s; | ||
} | ||
|
||
ifstream result;int deploy,m;string p; | ||
Big nbd ; | ||
|
||
string strip0(string s) | ||
{int i;i=0;while(s[i]=='0')i++;return s.substr(i);} | ||
|
||
bool printstringM(string s,string sr) | ||
{int i,j,ki,kj;char c; | ||
for(i=0;i<sr.length();i++)if(sr[i]=='{')break; | ||
else s=s+sr[i]; | ||
if(i<sr.length())sr=sr.substr(i+1,sr.length()-i);else sr=""; | ||
if(sr.empty()){nbd=0; for(j=0;j<s.length();j++) | ||
{c=s[j];nbd=nbd*m+w[c];} | ||
if(prime(nbd)) | ||
{cout<<'"'<<strip0(s)<<'"'<<'='<<s10(nbd)<<",\n";cerr<<'+'; | ||
cout.flush();return true;}return false;} | ||
c=sr[0];for(i=1;i<sr.length();i++)if(sr[i]=='}')break; | ||
sr=sr.substr(i+1,sr.length()-i); | ||
for(ki=0;ki<=deploy;ki++) | ||
{if((ki%1000)==0)cerr<<'-';else cerr<<'.';if(printstringM(s,sr))break; | ||
s=s+c; | ||
}return false; | ||
} | ||
|
||
main(int argc, char *argv[]) | ||
{string ms,pref,prefms; | ||
deploy=atoi(argv[argc-1]); | ||
ms=argv[1];m=atoi(argv[1]); | ||
for(char c='0';c<='9';c++){w[c]=0+c-'0';tr[0+c-'0']=c;} | ||
for(char c='A';c<='Z';c++){w[c]=10+c-'A';tr[10+c-'A']=c;} | ||
for(char c='a';c<='z';c++){w[c]=36+c-'a';tr[36+c-'a']=c;} | ||
while(cin>>p)if(p[0]=='%')break; | ||
else {cerr<<"\n"<<p<<"\n";printstringM("",p);} | ||
cerr<<"\n===================================\n"; | ||
} // fin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include "big.h" /* include MIRACL system */ | ||
using namespace std; | ||
|
||
Miracl precision(20000,128); /* bigs are 20000 centimal digits long */ | ||
|
||
char tr[128]; int w[128]; | ||
|
||
string s10(Big x) | ||
{Big y=x; int r; string s=""; | ||
while (y!=0){r=y%10;y=y/10;s=tr[r]+s;} | ||
return s; | ||
} | ||
|
||
ifstream result;int deploy,b,start,d,j;string ms,p,s,ss;char cc; | ||
Big nbd,n1,n2,pds; | ||
|
||
main(int argc, char *argv[]) | ||
{ | ||
deploy=atoi(argv[2]); | ||
ms=argv[1];b=atoi(argv[1]); | ||
if(argc>3)start=atoi(argv[3]);else start=0;cerr<<b<<','<<start<<','<<deploy<<"\n"; | ||
for(char c='0';c<='9';c++){w[c]=0+c-'0';tr[0+c-'0']=c;} | ||
for(char c='A';c<='Z';c++){w[c]=10+c-'A';tr[10+c-'A']=c;} | ||
for(char c='a';c<='z';c++){w[c]=36+c-'a';tr[36+c-'a']=c;} | ||
while(cin>>p)if(p[0]=='%')break; | ||
else {cerr<<"\n"<<p<<"\n";n1=0;n2=0;pds=1;s="";ss=""; | ||
for(j=0;j<p.size();j++)if(p[j]=='{')break; | ||
else {n1=n1*b+w[p[j]];s=s+p[j];} | ||
if(j==p.size()){cerr<<" : pas de repetition";continue;} | ||
cc=p[j+1];d=w[cc]; | ||
for(j=j+3;j<p.size();j++)if(p[j]=='{')break; | ||
else {n2=n2*b+w[p[j]];ss=ss+p[j];pds=pds*b;} | ||
if(j!=p.size()){cerr<<" : plus d'une repetition";continue;} | ||
for(j=0;j<start;j++){n1=n1*b+d;s=s+cc;} | ||
for(j=start;j<=deploy;j++) | ||
{nbd=n1*pds+n2; | ||
if(prime(nbd)) | ||
{cout<<'"'<<s+ss<<'"'<<'='<<s10(nbd)<<",\n";cerr<<'+';cout.flush();break;} | ||
else if((j%1000)==0)cerr<<'-';else cerr<<'.'; | ||
n1=n1*b+d;s=s+cc; | ||
} | ||
} | ||
cerr<<"\n===================================\n"; | ||
} // fin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include "big.h" /* include MIRACL system */ | ||
using namespace std; | ||
|
||
Miracl precision(20000,128); /* bigs are 10000 centimal digits long */ | ||
|
||
char tr[128]; int w[128]; | ||
|
||
string s10(Big x) | ||
{Big y=x; int r; string s=""; | ||
while (y!=0){r=y%10;y=y/10;s=tr[r]+s;} | ||
return s; | ||
} | ||
|
||
ifstream result;int deploy,m;string p; | ||
Big nbd ; | ||
|
||
string strip0(string s) | ||
{int i;i=0;while(s[i]=='0')i++;return s.substr(i);} | ||
|
||
void printstringM(string s,string sr,int n) | ||
{int i,j,ki,kj;char c;string ssr; | ||
cerr<<s<<'+'<<sr<<": "<<n<<"\n"; | ||
for(i=0;i<sr.length();i++)if(sr[i]=='{')break; | ||
else s=s+sr[i]; | ||
if(i<sr.length())sr=sr.substr(i+1,sr.length()-i);else sr=""; | ||
if(sr.empty()){nbd=0; for(j=0;j<s.length();j++) | ||
{c=s[j];nbd=nbd*m+w[c];} | ||
if(prime(nbd)) | ||
{cout<<'"'<<strip0(s)<<'"'<<'='<<s10(nbd)<<",\n"; | ||
cout.flush();}return; | ||
} | ||
if(sr[1]=='}') | ||
{c=sr[0];for(i=1;i<sr.length();i++)if(sr[i]=='}')break; | ||
sr=sr.substr(i+1,sr.length()-i); | ||
for(ki=0;ki<=deploy;ki++) | ||
{if((ki%1000)==0)cerr<<'-';else cerr<<'.'; | ||
printstringM(s,sr,deploy); | ||
s=s+c; | ||
}return; | ||
} else | ||
{for(i=1;i<sr.length();i++)if(sr[i]=='}')break; | ||
ssr=sr.substr(i+1,sr.length()-i); | ||
printstringM(s,ssr,deploy); | ||
if(n>0) | ||
for(i=0;sr[i]!='}';i++) printstringM(s+sr[i],'{'+sr,n-1); | ||
} | ||
} | ||
|
||
main(int argc, char *argv[]) | ||
{string ms,pref,prefms; | ||
deploy=atoi(argv[argc-1]); | ||
ms=argv[1];m=atoi(argv[1]); | ||
for(char c='0';c<='9';c++){w[c]=0+c-'0';tr[0+c-'0']=c;} | ||
for(char c='A';c<='Z';c++){w[c]=10+c-'A';tr[10+c-'A']=c;} | ||
for(char c='a';c<='z';c++){w[c]=36+c-'a';tr[36+c-'a']=c;} | ||
while(cin>>p)if(p[0]=='%')break; | ||
else {cerr<<"\n"<<p<<"\n";printstringM("",p,deploy);} | ||
cerr<<"\n===================================\n"; | ||
} // fin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <iomanip> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
|
||
#include <cmath> | ||
#include "big.h" /* include MIRACL system */ | ||
|
||
using namespace std; | ||
|
||
Miracl precision(5000,100); /* bigs are 5000 decimal digits long */ | ||
|
||
int deploy,b; string ms,p,s; Big NN,MM; | ||
char tr[128]; int w[128]; | ||
|
||
string s10(Big x) | ||
{Big y=x; int r; string s=""; | ||
while (y!=0){r=y%10;y=y/10;s=tr[r]+s;} | ||
return s; | ||
} | ||
string sb(Big x) | ||
{Big y=x; int r; string s=""; | ||
while (y!=0){r=y%b;y=y/b;s=tr[r]+s;} | ||
return s; | ||
} | ||
|
||
void printstringM(string s,string sr) | ||
{int i,j,ki,kj;char c; unsigned long int k; | ||
for(i=0;i<sr.length();i++)if(sr[i]=='{')break; | ||
else s=s+sr[i]; | ||
if(i<sr.length())sr=sr.substr(i+1,sr.length()-i);else sr=""; | ||
if(sr.empty()) | ||
{NN=0; for(j=0;j<s.length();j++) | ||
{c=s[j];kj=w[c];NN=NN*b+kj;} | ||
cout<<" "<<'"'<<p<<'"'<<"=>"<<'"'<<s<<'"'<<"= "<<s10(NN)<<"\n";MM=NN; | ||
if(NN==0)cout<<"is 0\n"; else | ||
if(NN==1)cout<<"is 1\n"; else | ||
if(prime(NN))cout<<"is prime\n"; else | ||
{k=2;while(!prime(NN)){while((NN%k)!=0){if(k>100000)break; else k++;} | ||
if(k<100000){cout<<sb(k)<<'('<<sb(MM/k)<<')'<<'.';NN=NN/k;cout.flush();}else break;} | ||
if(k<100000)cout<<sb(NN)<<'('<<sb(MM/NN)<<')'<<"\n";else cout<<"...\n";cout.flush();} | ||
return;} | ||
c=sr[0];for(i=1;i<sr.length();i++)if(sr[i]=='}')break; | ||
sr=sr.substr(i+1,sr.length()-i); | ||
for(ki=0;ki<=deploy;ki++) | ||
{printstringM(s,sr); | ||
s=s+c; | ||
} | ||
} | ||
|
||
main(int argc, char *argv[]) | ||
{ int k; char c; | ||
deploy=atoi(argv[argc-1]); | ||
ms=argv[1];b=atoi(argv[1]); | ||
for(char c='0';c<='9';c++){w[c]=0+c-'0';tr[0+c-'0']=c;} | ||
for(char c='A';c<='Z';c++){w[c]=10+c-'A';tr[10+c-'A']=c;} | ||
for(char c='a';c<='z';c++){w[c]=36+c-'a';tr[36+c-'a']=c;} | ||
while(cin>>p)if(p[0]=='%')break; | ||
else {s="";for(k=p.length()-1;k>=0;k--)if(p[k]=='}')if(p[k-2]!='{'){cerr<<p;break;} | ||
else {c=p[k-1];s='}'+s;s=c+s;s='{'+s;k=k-2;while(c==p[k-1])k--;} | ||
else s=p[k]+s;p=s; | ||
cout<<"===============================================\n";cerr<<s<<"\n";printstringM("",s);} | ||
} // fin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include "big.h" /* include MIRACL system */ | ||
using namespace std; | ||
|
||
Miracl precision(20000,100); /* bigs are 10000 centimal digits long */ | ||
|
||
string s10(Big x) | ||
{Big y=x; Big br; int r; string s=""; char c; | ||
while (y!=0){br=y%10;y=y/10; | ||
if(br==0)r=0;if(br==1)r=1;if(br==2)r=2;if(br==3)r=3;if(br==4)r=4;if(br==5)r=5; | ||
if(br==6)r=6;if(br==7)r=7;if(br==8)r=8;if(br==9)r=9;c='0'+r;s=c+s;}return s; | ||
} | ||
ifstream result;int deploy,b;string p; | ||
int w[128]; | ||
Big nbd ; | ||
string itos(int i) // convert int to string | ||
{stringstream s;s << i;return s.str();} | ||
|
||
string cvrt(char c) | ||
{if((c>='0')&&(c<='9')) return itos(c-'0'); else return itos(10+c-'A');} | ||
|
||
void printstringM(string s,string sr,int d) | ||
{int i,j,ki,kj,dd;string ll,ss;char c; | ||
for(i=0;i<sr.length();i++)if((sr[i]=='{')||(sr[i]=='<'))break; else s=s+sr[i]; | ||
if(i<sr.length())sr=sr.substr(i,sr.length()-i+1);else sr=""; | ||
if(sr.empty()){nbd=0; for(j=0;j<s.length();j++)nbd=nbd*b+w[s[j]]; | ||
if(prime(nbd)){cout<<'"'<<s<<'"'<<'='<<s10(nbd)<<",\n";cerr<<'+'; | ||
cout.flush();} | ||
return;} | ||
ll="";for(i=1;i<sr.length();i++)if((sr[i]=='}')||(sr[i]=='>'))break;else ll=ll+sr[i]; | ||
ss=sr.substr(i+1,sr.length()-i);printstringM(s,ss,d); | ||
if(!ll.empty()){dd=((d) / (ll.length()))-1; | ||
if(dd>=0) | ||
for(ki=0;ki<ll.length();ki++) | ||
{cerr<<'.';printstringM(s+ll[ki],sr,dd);}} | ||
} | ||
|
||
main(int argc, char *argv[]) | ||
{string ms,pref,prefms; | ||
deploy=atoi(argv[argc-1]); | ||
ms=argv[1];b=atoi(argv[1]); | ||
for(char c='0';c<='9';c++)w[c]=0+c-'0';for(char c='A';c<='Z';c++)w[c]=10+c-'A'; | ||
//while(cin>>p)if(p[0]=='%')break; | ||
while(cin>>p)if(p[0]=='%')break; | ||
else {cerr<<"\n"<<p;printstringM("",p,deploy);} | ||
cerr<<"\n===================================\n"; | ||
} // fin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <stdlib.h> | ||
using namespace std; | ||
|
||
ifstream kern; | ||
bool cover(string el1,string el2) | ||
{int i,j,k; | ||
if(el1.length()==el2.length())return false; | ||
if(el1.length()>el2.length())return(false); | ||
i=0;j=0; | ||
while(i<el1.length()) | ||
{if(el1[i]==el2[j]) | ||
{i++;j++;if(i==el1.length())return true;if(j>=el2.length())return false;} | ||
else{j++;if(j>=el2.length())return false;} | ||
} | ||
return true; | ||
} | ||
int order(string el1,string el2) | ||
{int i; | ||
if(el1.length()>el2.length())return 1; | ||
if(el1.length()<el2.length())return 2; | ||
i=0; | ||
while(i<el1.length()) | ||
{if(el1[i]==el2[i])i++; | ||
else if(el1[i]<el2[i])return 2; | ||
else return 1; | ||
} | ||
return 0; | ||
} | ||
main(int argc, char *argv[]) | ||
{string p,ms,pref,prefms,mm,m10,mM,md,s;int m,k,nn,nd,no,l,i,j; | ||
bool fin; char c; | ||
list<string> foundM,found10; | ||
list<string>::iterator itM,it10,fitM,fit10; | ||
for(k=1;k<argc;k++) | ||
{ms=argv[k];m=atoi(argv[k]); | ||
pref="kernel"; prefms=pref+ms; | ||
kern.open(prefms.c_str()); | ||
cout<<"M:="<<m<<":A:=10:C:=12:E:=14:F:=15:\n"; | ||
nn=0;nd=0;no=0; | ||
while(kern>>p) | ||
{nn++;l=p.length(); | ||
if(p[0]!='"'){cerr<<"problème de quote à la ligne"<<nn; } | ||
if(p[l-1]!=','){cerr<<"problème de , à la ligne"<<nn; } | ||
for(i=1;i<l;i++)if(p[i]=='"') | ||
{mm=p.substr(1,i-1);m10=p.substr(i+2,l-i-3);break;} | ||
if((nn>1)&&(order(found10.back(),m10)!=2)) | ||
{no++;//cerr<<"problème d'ordre à la ligne"<<nn; | ||
itM=foundM.begin();it10=found10.begin(); | ||
while(order(*it10,m10)==2){it10++;itM++;} | ||
if(order(*it10,m10)==1){foundM.insert(itM,mm);found10.insert(it10,m10);} | ||
} | ||
else{foundM.push_back(mm);found10.push_back(m10);} | ||
} | ||
nn==0;it10=found10.begin();itM=foundM.begin(); | ||
while(itM!=foundM.end()) | ||
{fitM=itM;fit10=it10;fitM++;fit10++; | ||
while(fitM!=foundM.end()) | ||
{if(cover(*itM,*fitM)) | ||
{nd++; //cerr<<*itM<<" domine "<<*fitM<<"\n"; | ||
fitM=foundM.erase(fitM);fit10=found10.erase(fit10);} | ||
else{fitM++;fit10++;} | ||
} | ||
itM++;it10++; | ||
} | ||
itM=foundM.begin();it10=found10.begin(); | ||
cerr<<"taille des listes: "<<foundM.size()<<","<<found10.size()<<"\n"; | ||
it10=found10.begin();itM=foundM.begin(); | ||
while(itM!=foundM.end()) | ||
{mM="0";for(i=0;i<(*itM).length();i++) | ||
{c=(*itM)[i];if((c>='0')&&(c<='9'))s=c; else {s='0'+(10+c-'A')/10;c='0'+(10+c-'A')%10;s=s+c;};mM="("+mM+")*M+"+s;} md=*it10; | ||
cout<<"[iszero("<<mM<<"-"<<md<<"),isprime("<<mM<<"),"<<mM<<","<<md<<"];\n"; | ||
itM++;it10++; | ||
} | ||
cerr<<" on a eu "<<no<<" problèmes d'ordre et "<<nd<<" problèmes de dominance"; | ||
}} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
using namespace std; | ||
|
||
ifstream kern,Q; ofstream resultchk,resultchkM,controlchk; | ||
bool cover(string el1,string el2) | ||
{int i,j,k; | ||
if(el1.length()==el2.length())return false; | ||
if(el1.length()>el2.length())return(false); | ||
i=0;j=0; | ||
while(i<el1.length()) | ||
{if(el1[i]==el2[j]) | ||
{i++;j++;if(i==el1.length())return true;if(j>=el2.length())return false;} | ||
else{j++;if(j>=el2.length())return false;} | ||
} | ||
return true; | ||
} | ||
int order(string el1,string el2) | ||
{int i; | ||
if(el1.length()>el2.length())return 1; | ||
if(el1.length()<el2.length())return 2; | ||
i=0; | ||
while(i<el1.length()) | ||
{if(el1[i]==el2[i])i++; | ||
else if(el1[i]<el2[i])return 2; | ||
else return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
string itos(int i) // convert int to string | ||
{stringstream s;s << i;return s.str();} | ||
|
||
string cvrt(char c) | ||
{if((c>='0')&&(c<='9')) return itos(c-'0'); else return itos(10+c-'A');} | ||
|
||
main(int argc, char *argv[]) | ||
{string p,ms,pref,prefms,mm,m10,mM,md;int m,k,nn,l,i,j; | ||
bool fin; | ||
list<string> foundM,found10; | ||
list<string>::iterator itM,it10,fitM,fit10; | ||
for(k=1;k<argc;k++) | ||
{ms=argv[k];m=atoi(argv[k]); | ||
pref="controlchk"; prefms=pref+ms; | ||
controlchk.open(prefms.c_str(),ios::out); | ||
pref="reschk"; prefms=pref+ms; | ||
resultchk.open(prefms.c_str(),ios::out); | ||
pref="kernel"; prefms=pref+ms; | ||
kern.open(prefms.c_str()); | ||
pref="Q"; prefms=pref+ms; | ||
Q.open(prefms.c_str()); | ||
pref="resultchkM"; prefms=pref+ms; | ||
resultchkM.open(prefms.c_str(),ios::out); | ||
resultchkM<<"M:="<<m<<":A:=10:C:=12:E:=14:F:=15:\n"; | ||
nn=0; | ||
while(kern>>p) | ||
{nn++;l=p.length(); | ||
if(p[0]!='"'){controlchk<<"problème de quote à la ligne"<<nn; } | ||
if(p[l-1]!=','){controlchk<<"problème de , à la ligne"<<nn; } | ||
for(i=1;i<l;i++)if(p[i]=='"') | ||
{mm=p.substr(1,i-1);m10=p.substr(i+2,l-i-3);break;} | ||
if((nn>1)&&(order(found10.back(),m10)!=2)) | ||
{controlchk<<"problème d'ordre à la ligne"<<nn; | ||
itM=foundM.begin();it10=found10.begin(); | ||
while(order(*it10,m10)==2){it10++;itM++;} | ||
if(order(*it10,m10)==1){foundM.insert(itM,mm);found10.insert(it10,m10);} | ||
} | ||
else{foundM.push_back(mm);found10.push_back(m10);} | ||
} | ||
nn==0;controlchk<<"taille des listes 1: "<<foundM.size()<<","<<found10.size()<<"\n"; | ||
fin=(Q>>p); | ||
while(fin) | ||
{nn++; | ||
while(p[0]!='t'){controlchk<<"problème de true à la ligne "<<nn<<" de Q\n"; | ||
fin=(Q>>p);if(!fin)break; }if(!fin)break; | ||
if(!(Q>>p))break;l=p.length(); | ||
if(p[0]!='"'){controlchk<<"problème de quote à la ligne "<<nn<<" de Q\n"; } | ||
else{for(i=1;i<l;i++){if(p[i]=='>')break;} | ||
for(j=i+1;j<l;j++) | ||
{if(p[j]=='='){mm=p.substr(i+1,j-i-1); | ||
fin=(Q>>p);m10=p;break;} } | ||
|
||
} | ||
if((m10[0]=='t')||(m10[0]=='"')) | ||
{controlchk<<"problème de m10 à la ligne "<<nn<<" de Q\n";} | ||
else {fin=(Q>>p);controlchk<<"???????"<<m10<<"\n"; | ||
if(order(found10.back(),m10)!=2) | ||
{itM=foundM.begin();it10=found10.begin(); | ||
while(order(*it10,m10)==2){it10++;itM++;} | ||
controlchk<<"inserer? "<<*it10<<"_"<<m10<<":"<<order(*it10,m10)<<"\n"; | ||
if(order(*it10,m10)==1){foundM.insert(itM,mm);found10.insert(it10,m10); | ||
cout<<*it10<<"<"<<m10<<"\n";} | ||
else controlchk<<"======="<<*it10<<"_"<<m10<<"\n"; | ||
} | ||
else{foundM.push_back(mm);found10.push_back(m10); | ||
controlchk<<'"'<<mm<<'"'<<'='<<m10<<"\n";} | ||
} | ||
} | ||
controlchk<<"taille des listes 2: "<<foundM.size()<<","<<found10.size()<<"\n"; | ||
it10=found10.begin();itM=foundM.begin(); | ||
while(itM!=foundM.end()) | ||
{fitM=itM;fit10=it10;fitM++;fit10++; | ||
while(fitM!=foundM.end()) | ||
{if(cover(*itM,*fitM)) | ||
{controlchk<<*itM<<" domine "<<*fitM<<"\n";controlchk.flush(); | ||
fitM=foundM.erase(fitM);fit10=found10.erase(fit10);} | ||
else{fitM++;fit10++;} | ||
} | ||
itM++;it10++; | ||
} | ||
itM=foundM.begin();it10=found10.begin(); | ||
controlchk<<"taille des listes: "<<foundM.size()<<","<<found10.size()<<"\n"; | ||
it10=found10.begin();itM=foundM.begin(); | ||
while(itM!=foundM.end()) | ||
{resultchk<<'"'<<*itM<<'"'<<'='<<*it10<<",\n"; | ||
mM="0";for(i=0;i<(*itM).length();i++){mM="("+mM+")*M+"+cvrt((*itM)[i]);} md=*it10; | ||
resultchkM<<"[testeq("<<mM<<","<<md<<"),isprime("<<mM<<"),"<<mM<<","<<md<<"];\n"; | ||
itM++;it10++; | ||
} | ||
//for(itM=foundM.begin();itM!=foundM.end();itM++)controlchk<<*itM<<","; | ||
|
||
controlchk.close();resultchk.close();kern.close();resultchkM.close(); | ||
}} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include <stdlib.h> | ||
using namespace std; | ||
|
||
struct elem{string mm, m10;}; | ||
list<elem> found; elem el; | ||
|
||
ifstream kern; ofstream ckern; | ||
bool cover(string el1,string el2) | ||
{int i,j,k; | ||
if(el1.length()==el2.length())return false; | ||
if(el1.length()>el2.length())return(false); | ||
i=0;j=0; | ||
while(i<el1.length()) | ||
{if(el1[i]==el2[j]) | ||
{i++;j++;if(i==el1.length())return true;if(j>=el2.length())return false;} | ||
else{j++;if(j>=el2.length())return false;} | ||
} | ||
return true; | ||
} | ||
int order(string el1,string el2) | ||
{int i; | ||
if(el1.length()>el2.length())return 1; | ||
if(el1.length()<el2.length())return 2; | ||
i=0; | ||
while(i<el1.length()) | ||
{if(el1[i]==el2[i])i++; | ||
else if(el1[i]<el2[i])return 2; | ||
else return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
string itos(int i) // convert int to string | ||
{stringstream s;s << i;return s.str();} | ||
|
||
string cvrt(char c) | ||
{if((c>='0')&&(c<='9')) return itos(c-'0'); else return itos(10+c-'A');} | ||
|
||
main(int argc, char *argv[]) | ||
{string p,ms,pref,prefms,mm,m10,mM,md;int m,k,nn,l,i,j; | ||
bool fin; | ||
list<string> foundM,found10; | ||
list<elem>::iterator it,itp; | ||
for(k=1;k<argc;k++) | ||
{ms=argv[k];m=atoi(argv[k]); | ||
pref="kernel"; prefms=pref+ms; | ||
kern.open(prefms.c_str()); | ||
nn=0; | ||
while(kern>>p) | ||
{nn++;if((nn%10000)==0)cerr<<ms<<":"<<p<<"\n"; | ||
l=p.length(); | ||
if(p[0]!='"'){cout<<"problème de quote à la ligne"<<p; } | ||
if(p[l-1]!=','){p=p+",";cout<<"problème de , à la ligne"<<p; } | ||
for(i=1;i<l;i++)if(p[i]=='>') | ||
{p='"'+p.substr(i+1,l-1);l=p.length();break;} | ||
for(i=1;i<l;i++)if(p[i]=='"') | ||
{mm=p.substr(1,i-1);m10=p.substr(i+2,l-i-3);break;} | ||
for(it=found.begin();it!=found.end();it++)if(cover((*it).mm,mm))break; | ||
if(it==found.end()) | ||
{it=found.begin();while(it!=found.end()) | ||
{if(cover(mm,(*it).mm))it=found.erase(it); else it++;} | ||
for(it=found.begin();it!=found.end();it++) | ||
{if(order(mm,(*it).mm)==0)break; | ||
if(order(mm,(*it).mm)==2) | ||
{el.mm=mm;el.m10=m10;found.insert(it,el);break;} | ||
} | ||
if(it==found.end()){el.mm=mm;el.m10=m10;found.push_back(el);} | ||
} | ||
} | ||
while(cin>>p) | ||
{nn++;if((nn%10000)==0)cerr<<ms<<":"<<p<<"("<<found.size()<<")\n"; | ||
l=p.length(); | ||
if(p[0]!='"'){cout<<"problème de quote à la ligne"<<p; } | ||
if(p[l-1]!=','){p=p+",";cout<<"problème de , à la ligne"<<p; } | ||
for(i=1;i<l;i++)if(p[i]=='>') | ||
{p='"'+p.substr(i+1,l-1);l=p.length();break;} | ||
for(i=1;i<l;i++)if(p[i]=='"') | ||
{mm=p.substr(1,i-1);m10=p.substr(i+2,l-i-3);break;} | ||
for(it=found.begin();it!=found.end();it++)if(cover((*it).mm,mm))break; | ||
if(it==found.end()) | ||
{it=found.begin();while(it!=found.end()) | ||
{if(cover(mm,(*it).mm))it=found.erase(it); else it++;} | ||
for(it=found.begin();it!=found.end();it++) | ||
{if(order(mm,(*it).mm)==0)break; | ||
if(order(mm,(*it).mm)==2) | ||
{el.mm=mm;el.m10=m10;found.insert(it,el);break;} | ||
} | ||
if(it==found.end()){el.mm=mm;el.m10=m10;found.push_back(el);} | ||
} | ||
} | ||
for(it=found.begin();it!=found.end();it++) | ||
cout<<'"'<<(*it).mm<<'"'<<'='<<(*it).m10<<",\n"; | ||
kern.close(); | ||
}} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include <stdlib.h> | ||
using namespace std; | ||
|
||
struct elem{string mm;}; | ||
list<elem> found;elem el; | ||
|
||
ifstream kern; ofstream ckern; | ||
bool cover(string el1,string el2) | ||
{int i,j; | ||
if(el1.length()==el2.length())return false; | ||
if(el1.length()>el2.length())return(false); | ||
i=0;j=0; | ||
while(i<el1.length()) | ||
{if(el1[i]==el2[j]) | ||
{i++;j++;if(i==el1.length())return true;if(j>=el2.length())return false;} | ||
else{j++;if(j>=el2.length())return false;} | ||
} | ||
return true; | ||
} | ||
|
||
main(int argc, char *argv[]) | ||
{string p,pp,ms,pref,prefms;int m,l,i,j; | ||
bool fin; | ||
list<string> foundM,found10; | ||
list<elem>::iterator it,itp; | ||
{ms=argv[1]; | ||
pref="kernel"; prefms=pref+ms; | ||
kern.open(prefms.c_str()); | ||
m=atoi(argv[2]); | ||
while(kern>>p){pp="";l=1;while(p[l]!='"'){pp=pp+p[l];l++;} | ||
el.mm=pp;found.push_back(el);} | ||
while(cin>>p) | ||
{l=0;pp=""; | ||
while(p[l]!='{'){pp=pp+p[l];l++;} | ||
if(p[l+2]!='}'){cerr<<"ERREUR 0:"<<p<<"\n";break;} | ||
for(i=1;i<=m;i++){pp=pp+p[l+1];}l=l+3; | ||
while(l<p.length()){pp=pp+p[l];l++;} | ||
for(it=found.begin();it!=found.end();it++)if(cover((*it).mm,pp))break; | ||
if(it==found.end())cerr<<p<<"\n"; else cout<<p<<"\n"; | ||
} | ||
kern.close(); | ||
}} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#include <string> | ||
#include <list> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#define wide 25000 | ||
|
||
using namespace std; | ||
unsigned int m; | ||
struct elem{unsigned long int n; | ||
list<short int> t; | ||
list <list<short int>::iterator> ptr; | ||
list<short int> next; | ||
}; | ||
string tr; | ||
ofstream kern,P; | ||
|
||
void printelem(elem el) | ||
{list<short int>::iterator iti; short int si; | ||
list <list<short int>::iterator>::iterator ititi; | ||
kern<<'"'; | ||
for (iti=el.t.begin();iti!=el.t.end();++iti) | ||
{si=*iti ; if(m<=36){kern<<tr[si];} | ||
else{kern<<si<<",";} | ||
} | ||
kern<<'"'<<"="<<el.n; | ||
kern<<",\n";kern.flush();} | ||
|
||
unsigned int min(unsigned int i, unsigned int j) | ||
{if(i<=j)return i;else return j;} | ||
|
||
bool ok(long int n) // is composite? | ||
{unsigned int kk; | ||
if (n<4) return false; | ||
for (kk=2;kk*kk<=n;kk++) | ||
{if(n % kk==0)return true;} | ||
return false; | ||
} | ||
|
||
short int si,f,i,j,iinit; | ||
unsigned int g,gg,t1,ll,kk; | ||
unsigned long int ni,n,nmax,nn,szm,nn0; | ||
int cpustart; double cptime; | ||
elem el,el1; | ||
list<elem> todo, found; | ||
list<elem>::iterator ite,ite1,ite2; | ||
list<short int>::iterator iti,iti1,iti2; | ||
list<list<short int>::iterator>::iterator ite3,ite4; | ||
|
||
void handlebase(unsigned int m) | ||
{ | ||
cpustart=clock(); | ||
nmax=0;nn=m-1; | ||
todo.clear(); found.clear(); tr=""; | ||
for (i=0;i<min(m,10);i++)tr.push_back('0'+i); | ||
for (i=10;i<m;i++)tr.push_back('A'+i-10); | ||
|
||
P<<"\nbase="<<m<<":\n"; | ||
kern<<"\nbase="<<m<<":\n"; | ||
for (i=1;i<m;i++) | ||
{el.n=i; el.t.clear();el.t.push_back(i); el.ptr.clear();el.next.clear(); | ||
if (ok(i)) {found.push_back(el);printelem(el);} | ||
else{todo.push_back(el);}} | ||
for (ite1=todo.begin();ite1!=todo.end();++ite1) | ||
{(*ite1).next.push_back(0);(*ite1).next.push_back(1); | ||
for (i=2;i<m;i++){if(!ok(i)){(*ite1).next.push_back(i);}} | ||
for (ite2=found.begin();ite2!=found.end();++ite2) | ||
{(*ite1).ptr.push_back((*ite2).t.begin());} | ||
} | ||
// les structures sont initialisées, avec les chiffres de la base | ||
szm=todo.size(); | ||
while (!todo.empty()) // tant qu'il y a des todo | ||
{el=todo.front();ni=el.n; | ||
if(((((ni+1)*m)/m)!=(ni+1))// (ni>over) | ||
||(todo.size()>wide))break; // si trop long ou trop large: on arr\^ete! | ||
else{todo.pop_front(); | ||
ite1=found.end();ite3=el.ptr.end();j=found.size()-el.ptr.size(); | ||
for (i=1;i<=j;i++) // s'il y a de nouveaux founds, on ajuste les structures | ||
{ite1--; iti1=(*ite1).t.begin();iti2=el.t.begin(); | ||
while(iti2!=el.t.end()){if((*iti1)==(*iti2)){iti1++;iti2++;}else{iti2++;}} | ||
ite3=el.ptr.insert(ite3,iti1); | ||
} | ||
for (iti=el.next.begin();iti!=el.next.end();iti++) // le préfixe considéré est allongé | ||
{el1=el;i=*iti;n=ni*m+i;el1.n=n;el1.t.push_back(i);nmax=n; | ||
ite1=found.begin(); nn++; | ||
for (ite3=el1.ptr.begin();ite3!=el1.ptr.end();ite3++) | ||
{if(i==(*(*ite3))){(*ite3)++; | ||
if((*ite3)==(*ite1).t.end())break;} | ||
ite1++; | ||
} | ||
if(ite3==el1.ptr.end()) | ||
{ // il n'est pas couvert | ||
if (ok(n)) | ||
{found.push_back(el1);printelem(el1);} // il est found | ||
else todo.push_back(el1); | ||
} | ||
if(todo.size()>szm)szm=todo.size(); | ||
} // fin de la boucle d'allongement | ||
}} // fin de la boucle sur todo | ||
// | ||
cptime = (clock()-cpustart)/1000000.0; | ||
P<<"\nla taille de la base de composites est de : "<<found.size(); | ||
P<<"\nil a fallu "<<cptime<<" secondes pour les obtenir, considerer "<<nn<<" candidats, dont "<<szm<<" en meme temps."; | ||
P<<"\nle plus grand entier traite est : "<<nmax; | ||
if(!todo.empty()){ | ||
P<<"\n_____________________________________________________"; | ||
P<<"\nil restait encore "<<todo.size()<<" prefixes à traiter\n"; | ||
P<<"\n===============================================\n"; | ||
} | ||
P<<"\n\\put("<<3*m<<",0){\\line(0,1){"<<found.size()/6.0<<"}} %"<<m<<"\n"; | ||
P<<"\n\n\n";P.flush(); | ||
} | ||
int main(int argc, char *argv[]) | ||
{ | ||
kern.open("l-composites",ios::out); | ||
P.open("o-composites",ios::out); | ||
for(m=2;m<=100;m++) | ||
handlebase(m); | ||
P.close();kern.close(); | ||
} // fin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <list> | ||
#include <string> | ||
#include <vector> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include <stdlib.h> | ||
|
||
#include "big.h" /* include MIRACL system */ | ||
|
||
#define cyclemax 12 | ||
#define bound 1000000 | ||
|
||
using namespace std; | ||
|
||
Miracl precision(20000,128); /* bigs are 20000 decimal digits long */ | ||
|
||
int b,i,j,ki,kj,r,rr,k,kk,i1,h,pp; string p; | ||
vector <int> prm; | ||
int fact[cyclemax][cyclemax]; | ||
Big NN; | ||
|
||
char tr[128]; int w[128]; | ||
|
||
main(int argc, char *argv[]) | ||
{string ms,pref,prefms,p; | ||
ms=argv[1];b=atoi(argv[1]); | ||
prm.push_back(2);k=3;while(k<bound){NN=k;if(prime(NN))prm.push_back(k);k=k+2;} | ||
for(char c='0';c<='9';c++){w[c]=0+c-'0';tr[0+c-'0']=c;} | ||
for(char c='A';c<='Z';c++){w[c]=10+c-'A';tr[10+c-'A']=c;} | ||
for(char c='a';c<='z';c++){w[c]=36+c-'a';tr[36+c-'a']=c;} | ||
while(cin>>p) | ||
{cerr<<"\n"<<p; | ||
for(i=1;i<=cyclemax;i++) | ||
{for (j=1;j<=cyclemax;j++) | ||
{for(ki=0;ki<i;ki++)for(kj=0;kj<j;kj++)fact[ki][kj]=0; | ||
for(ki=0;ki<i;ki++) | ||
{for(kj=0;kj<j;kj++) | ||
{for(k=0;k<prm.size();k++) | ||
{kk=prm[k];r=0; | ||
for(i1=0;p[i1]!='{';i1++)r=(r*b+w[p[i1]])%kk;pp=w[p[i1+1]]; | ||
for(h=0;h<ki;h++)r=(r*b+pp)%kk;rr=r; | ||
for(h=1;h<=i;h++)rr=(rr*b+pp)%kk;if(rr!=r)continue; | ||
for(i1=i1+3;p[i1]!='{';i1++)r=(r*b+w[p[i1]])%kk;pp=w[p[i1+1]]; | ||
for(h=0;h<kj;h++)r=(r*b+pp)%kk;rr=r; | ||
for(h=1;h<=j;h++)rr=(rr*b+pp)%kk;if(rr!=r)continue; | ||
for(i1=i1+3;i1<p.length();i1++)r=(r*b+w[p[i1]])%kk;if(r!=0)continue; | ||
fact[ki][kj]=kk;break; | ||
} | ||
if(k==prm.size())break; | ||
} | ||
if(k==prm.size())break; | ||
} | ||
if(k==prm.size())continue; | ||
cerr<<"\ncycle double:\n";for(ki=0;ki<i;ki++){for(kj=0;kj<j;kj++)cerr<<fact[ki][kj]<<',';cerr<<'\n';}break; | ||
} | ||
if(k<prm.size())break; | ||
} | ||
if(k==prm.size())cout<<p<<'\n'; | ||
cerr<<"\n===================================\n"; | ||
} | ||
} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
#include <list> | ||
#include <string> | ||
#include <vector> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include <stdlib.h> | ||
|
||
#include "big.h" /* include MIRACL system */ | ||
|
||
#define cyclemax 12 | ||
#define bound 1000000 | ||
|
||
using namespace std; | ||
|
||
Miracl precision(20000,128); /* bigs are 20000 decimal digits long */ | ||
|
||
int b,ite,n1,n2,i,j,k,h,l,m,r,i1,i2,d,dd,jj,ddd,decal; char c; string s,ss,sss; | ||
vector <int> fact;vector <int> prm; | ||
int f[128]; | ||
string divfound[cyclemax+1][cyclemax+1]; | ||
Big polyn[100], polfact1[100], polfact2[100]; | ||
Big NN,Nd,Ni,Fi,Ib,Nf,Ff,N1,MM,Fb,Fc,Ma,Mb,Mc,Maa,Mbb,Faa,Fbb,X,Y,Z,FZ,L2,Ndd; | ||
vector <Big> factors; | ||
|
||
char tr[128]; int w[128]; | ||
|
||
string sb(Big x) | ||
{Big y=x; int r; string s=""; char c; | ||
while (y!=0){r=y%b;y=y/b;s=tr[r]+s;}return s; | ||
} | ||
string sb0(Big x) | ||
{Big y=x; int r; string s=""; char c; | ||
if(x==0)return "0"; | ||
while (y!=0){r=y%b;y=y/b;s=tr[r]+s;}return s; | ||
} | ||
string s10(Big x) | ||
{Big y=x; int r; string s=""; char c; | ||
if(x==0)return "0"; | ||
while (y!=0){r=y%10;y=y/10;s=tr[r]+s;}return s; | ||
} | ||
string check0() | ||
{Ndd=Nd; | ||
for(decal=0;decal<5;decal++) | ||
{ | ||
{for(ite=0;ite<fact.size();ite++) | ||
{i=fact[ite];n1=Ndd%i;n2=(n1*Ff+Nf)%i; | ||
if((n2==0)&&(((n1*Fi+Ni)%i)==n1))break; | ||
} | ||
if(ite!=fact.size()){return sb(i);} | ||
N1=Ndd*Ff+Nf;if(N1==0)continue; | ||
if(prime(N1)){cerr<<"\nnouveau premier trouvé:"<<sb(N1);return sb(N1);} | ||
j=0;MM=N1;factors.clear();factors.push_back(1); | ||
while((j<prm.size())&&(MM!=1))if((MM%prm[j])==0) | ||
{k=factors.size(); | ||
for(i=0;i<k;i++) | ||
{for(h=0;h<factors.size();h++)if(factors[h]==(factors[i]*prm[j]))break; | ||
if(h==factors.size())factors.push_back(factors[i]*prm[j]); | ||
} | ||
MM=MM/prm[j]; | ||
} | ||
else j++; | ||
for(i=0;i<factors.size();i++) | ||
{s=sb(factors[i]);ss=sb(N1/factors[i]); | ||
for(j=0;j<=s.length();j++) | ||
{Ma=0;for(k=0;k<j;k++)Ma=Ma*b+w[s[k]]; | ||
Mc=0;Fc=1; | ||
for(k=j;k<s.length();k++){Fc=Fc*b;Mc=Mc*b+w[s[k]];} | ||
for(dd=0;dd<b;dd++) | ||
{Mb=0;Fb=1;if((dd==0)&&(j==0))continue; | ||
for(h=1;h<m;h++) | ||
{Mb=Mb*b+dd;Fb=Fb*b;X=Ndd;Y=Ma; | ||
for(l=0;l<20;l++) | ||
{X=X*Fi+Ni;Y=Y*Fb+Mb;if(((X*Ff+Nf)%(Y*Fc+Mc))!=0)break; | ||
} | ||
if(l==20){s=sb((X*Ff+Nf)/(Y*Fc+Mc));ss=""; | ||
cerr<<"\n"<<sb(Y*Fc+Mc)<<"*"<<s<<" = "<<sb(X*Ff+Nf); | ||
for(i=0;i<=m;i++){polyn[i]=0;polfact1[i]=0;polfact2[i]=0;} | ||
polyn[m]=Ndd*Ff*(b-1)*(b-1)+d*Ff*(b-1); | ||
polyn[0]=Nf*(b-1)*(b-1)-d*Ff*(b-1); | ||
polfact1[h]=Ma*Fc*(b-1)+dd*Fc; | ||
polfact1[0]=Mc*(b-1)-dd*Fc;L2=1;j=0; | ||
for(i=s.length()-1;i>=0;i--) | ||
{for(k=1;(k<=19)&&(i>=k);k++)if(s[i-k]!=s[i])break; | ||
if(k<=19){if(k>=15){polfact2[j]=polfact2[j]-w[s[i]]*L2; | ||
sss=s[i];sss="{"+sss+"}";i=i-k+1; | ||
for(k=k;k<=19;k++){sss=sss+'-';L2=L2/b;} | ||
for(k=0;k<decal;k++)sss=sss+'-'; | ||
ss=sss+ss; | ||
j++;polfact2[j]=w[s[i]]*L2; | ||
} | ||
else {ss=s[i]+ss; | ||
polfact2[j]=polfact2[j]+w[s[i]]*(b-1)*L2;L2=L2*b; | ||
} | ||
} | ||
else{sss=s[i];sss="{"+sss;sss=sss+'}'; | ||
for(k=0;k<decal;k++)sss=sss+'-'; | ||
ss=sss+ss; | ||
polfact2[j]=polfact2[j]-w[s[i]]*L2; | ||
j++;polfact2[j]=w[s[i]]*L2;i=i-19; | ||
} | ||
} | ||
for(k=i;k>=0;k--){ss=s[k]+ss; | ||
polfact2[j]=polfact2[j]+w[s[k]]*(b-1)*L2; | ||
L2=L2*b; | ||
} | ||
for(i=0;i<=m;i++){X=polyn[i];for(j=0;j<=i;j++) | ||
X=X-polfact1[j]*polfact2[i-j]; | ||
if(X!=0){cerr<<"\n%%% : "; | ||
for(j=0;j<=m;j++)cerr<<polyn[m-j]<<','; | ||
cerr<<"\n : "; | ||
for(j=0;j<=m;j++)cerr<<polfact1[m-j]<<','; | ||
cerr<<"\n : "; | ||
for(j=0;j<=m;j++)cerr<<polfact2[m-j]<<','; | ||
break; | ||
} | ||
} | ||
ss=sb(Mc)+"]*["+ss+']';for(decal=decal;decal>0;decal--)ss='-'+ss; | ||
return ('['+sb(Ma)+'{'+sb0(Mb)+'}'+ss); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
N1=Ndd*Ff+Nf;if(m>=4) | ||
for(i=0;i<factors.size();i++) | ||
{s=sb(factors[i]);ss=sb(N1/factors[i]); | ||
for(j=0;j<=s.length();j++) | ||
{Ma=0;for(k=0;k<j;k++)Ma=Ma*b+w[s[k]]; | ||
for(jj=j;jj<=s.length();jj++) | ||
{Maa=0;Faa=1;for(k=j;k<jj;k++){Maa=Maa*b+w[s[k]];Faa=Faa*b;} | ||
Mc=0;Fc=1; | ||
for(k=jj;k<s.length();k++){Fc=Fc*b;Mc=Mc*b+w[s[k]];} | ||
for(dd=0;dd<b;dd++){if((dd==0)&&(j==0))continue;for(ddd=0;ddd<b;ddd++) | ||
{Mb=0;Fb=1;Mbb=0;Fbb=1; | ||
//for(h=1;h<m;h++) | ||
{Mb=Mb*b+dd;Fb=Fb*b;Mbb=Mbb*b+ddd;Fbb=Fbb*b;X=Ndd;Y=Ma;Z=Maa;FZ=Faa; | ||
for(l=0;l<20;l++) | ||
{X=X*Fi+Ni;Y=Y*Fb+Mb;Z=Z*Fbb+Mbb;FZ=FZ*Fbb; | ||
if(((X*Ff+Nf)%((Y*FZ+Z)*Fc+Mc))!=0)break;} | ||
if(l==20){s=sb((X*Ff+Nf)/((Y*FZ+Z)*Fc+Mc));ss="";cerr<<"\n$ : "<<sb(Fi); | ||
cerr<<"\n"<<sb((Y*FZ+Z)*Fc+Mc)<<"*"<<s<<" = "<<sb(X*Ff+Nf); | ||
for(i=0;i<=m;i++){polyn[i]=0;polfact1[i]=0;polfact2[i]=0;} | ||
polyn[m]=Ndd*Ff*(b-1)*(b-1)+d*Ff*(b-1); | ||
polyn[0]=Nf*(b-1)*(b-1)-d*Ff*(b-1); | ||
polfact1[h]=Ma*Fc*(b-1)+dd*Fc; //à adapter | ||
polfact1[0]=Mc*(b-1)-dd*Fc;L2=1;j=0; | ||
for(i=s.length()-1;i>=19;i--) | ||
{for(k=1;k<=19;k++)if(s[i-k]!=s[i])break; | ||
if(k<=19){if(k>=15){polfact2[j]=polfact2[j]-w[s[i]]*L2; | ||
sss=s[i];sss="{"+sss+"}";i=i-k+1; | ||
for(k=k;k<=19;k++){sss=sss+'-';L2=L2/b;} | ||
ss=sss+ss; | ||
j++;polfact2[j]=w[s[i]]*L2; | ||
} | ||
else {ss=s[i]+ss; | ||
polfact2[j]=polfact2[j]+w[s[i]]*(b-1)*L2;L2=L2*b; | ||
} | ||
} | ||
else{sss=s[i];sss="{"+sss;ss=sss+'}'+ss; | ||
polfact2[j]=polfact2[j]-w[s[i]]*L2; | ||
j++;polfact2[j]=w[s[i]]*L2;i=i-19; | ||
} | ||
} | ||
for(k=i;k>=0;k--){ss=s[k]+ss; | ||
polfact2[j]=polfact2[j]+w[s[k]]*(b-1)*L2; | ||
L2=L2*b; | ||
} | ||
for(i=0;i<=m;i++){X=polyn[i];for(j=0;j<=i;j++) | ||
X=X-polfact1[j]*polfact2[i-j]; | ||
if(X!=0){cerr<<"\n%%% : "; | ||
for(j=0;j<=m;j++)cerr<<polyn[m-j]<<','; | ||
cerr<<"\n : "; | ||
for(j=0;j<=m;j++)cerr<<polfact1[m-j]<<','; | ||
cerr<<"\n : "; | ||
for(j=0;j<=m;j++)cerr<<polfact2[m-j]<<','; | ||
break; | ||
} | ||
} | ||
return ('['+sb(Ma)+'{'+sb0(Mb)+'}'+sb(Maa)+'{'+sb0(Mbb)+'}'+sb(Mc)+"]*["+ss+']'); | ||
} | ||
} | ||
}} | ||
} | ||
} | ||
} | ||
} | ||
Ndd=Ndd*Fi+Ni; | ||
} | ||
return ""; | ||
} | ||
bool ok(long int n) // is prime? | ||
{unsigned int kk; | ||
if (n<2) return false; | ||
for (kk=2;kk*kk<=n;kk++) | ||
{if(n % kk==0)return false;} | ||
return true; | ||
} | ||
|
||
main(int argc, char *argv[]) | ||
{string ms,pref,prefms,p; | ||
ms=argv[1];b=atoi(argv[1]); | ||
for(i=2;i<b*b*b*b;i++)if(ok(i))fact.push_back(i); | ||
k=2;while(k<bound){NN=k;if(prime(NN))prm.push_back(k);k++;} | ||
for(char c='0';c<='9';c++){w[c]=0+c-'0';tr[0+c-'0']=c;} | ||
for(char c='A';c<='Z';c++){w[c]=10+c-'A';tr[10+c-'A']=c;} | ||
for(char c='a';c<='z';c++){w[c]=36+c-'a';tr[36+c-'a']=c;} | ||
while(cin>>p) | ||
{//if(p[0]=='{')p=p[1]+p;if(p[p.length()-1]=='}')p=p+p[p.length()-2]; | ||
cerr<<"\n"<<p; | ||
NN=0;for(i1=0;p[i1]!='{';i1++)NN=NN*b+w[p[i1]];d=w[p[i1+1]]; | ||
Nf=0;Ff=1;for(i1=i1+3;i1<p.length();i1++){Ff=Ff*b;Nf=Nf*b+w[p[i1]];} | ||
Ni=0;Fi=1; | ||
for(i=0;i<=cyclemax;i++)for(j=0;j<cyclemax;j++)divfound[i][j]=""; | ||
for(m=1;m<=cyclemax;m++) | ||
{Ni=Ni*b+d;Fi=Fi*b;Nd=NN; | ||
for(r=0;r<m;r++) | ||
{if(divfound[m][r]=="") | ||
{divfound[m][r]=check0(); | ||
if(divfound[m][r]!="") | ||
{cerr<<"\ndiv "<<divfound[m][r]<<" pour i="<<r<<" mod("<<m<<")"; | ||
for(j=2;(j*m)<=cyclemax;j++) | ||
for(k=0;k<j;k++) | ||
if(divfound[j*m][r+k*m]=="")divfound[j*m][r+k*m]=divfound[m][r]; | ||
for(i=0;i<m;i++)if(divfound[m][i]=="")break; | ||
if(i==m){cerr<<"\n"<<p<<" => cycle de taille "<<m<<" : "; | ||
for(i=0;i<m;i++)cerr<<divfound[m][i]<<',';break; | ||
} | ||
} | ||
} | ||
Nd=Nd*b+d; | ||
} | ||
if(r!=m)break; | ||
} | ||
if(m>cyclemax)cout<<p<<"\n"; | ||
cerr<<"\n===================================\n"; | ||
} | ||
} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
#include <list> | ||
#include <string> | ||
#include <vector> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include <stdlib.h> | ||
|
||
#include "big.h" /* include MIRACL system */ | ||
|
||
#define cyclemax 8 | ||
#define bound 1000000 | ||
|
||
using namespace std; | ||
|
||
Miracl precision(20000,128); /* bigs are 20000 decimal digits long */ | ||
|
||
int b,ite,n1,n2,i,j,k,h,l,m,r,i1,i2,d,dd,jj,ddd,decal; char c; string s,ss,sss; | ||
vector <int> fact;vector <int> prm; | ||
int f[128]; | ||
string divfound[cyclemax+1][cyclemax+1]; | ||
Big polyn[100], polfact1[100], polfact2[100]; | ||
Big NN,Nd,Ni,Fi,Ib,Nf,Ff,N1,MM,Fb,Fc,Ma,Mb,Mc,Maa,Mbb,Faa,Fbb,X,Y,Z,FZ,L2,Ndd; | ||
vector <Big> factors; | ||
|
||
char tr[128]; int w[128]; | ||
|
||
string sb(Big x) | ||
{Big y=x; int r; string s=""; char c; | ||
while (y!=0){r=y%b;y=y/b;s=tr[r]+s;}return s; | ||
} | ||
string sb0(Big x) | ||
{Big y=x; int r; string s=""; char c; | ||
if(x==0)return "0"; | ||
while (y!=0){r=y%b;y=y/b;s=tr[r]+s;}return s; | ||
} | ||
string s10(Big x) | ||
{Big y=x; int r; string s=""; char c; | ||
if(x==0)return "0"; | ||
while (y!=0){r=y%10;y=y/10;s=tr[r]+s;}return s; | ||
} | ||
string check0() | ||
{Ndd=Nd; | ||
for(decal=0;decal<5;decal++) | ||
{ | ||
{for(ite=0;ite<fact.size();ite++) | ||
{i=fact[ite];n1=Ndd%i;n2=(n1*Ff+Nf)%i; | ||
if((n2==0)&&(((n1*Fi+Ni)%i)==n1))break; | ||
} | ||
if(ite!=fact.size()){return sb(i);} | ||
N1=Ndd*Ff+Nf;if(N1==0)continue; | ||
if(prime(N1)){cerr<<"\nnouveau premier trouvé:"<<sb(N1);return sb(N1);} | ||
j=0;MM=N1;factors.clear();factors.push_back(1); | ||
while((j<prm.size())&&(MM!=1))if((MM%prm[j])==0) | ||
{k=factors.size(); | ||
for(i=0;i<k;i++) | ||
{for(h=0;h<factors.size();h++)if(factors[h]==(factors[i]*prm[j]))break; | ||
if(h==factors.size())factors.push_back(factors[i]*prm[j]); | ||
} | ||
MM=MM/prm[j]; | ||
} | ||
else j++; | ||
for(i=0;i<factors.size();i++) | ||
{s=sb(factors[i]);ss=sb(N1/factors[i]); | ||
for(j=0;j<=s.length();j++) | ||
{Ma=0;for(k=0;k<j;k++)Ma=Ma*b+w[s[k]]; | ||
Mc=0;Fc=1; | ||
for(k=j;k<s.length();k++){Fc=Fc*b;Mc=Mc*b+w[s[k]];} | ||
for(dd=0;dd<b;dd++) | ||
{Mb=0;Fb=1;if((dd==0)&&(j==0))continue; | ||
for(h=1;h<m;h++) | ||
{Mb=Mb*b+dd;Fb=Fb*b;X=Ndd;Y=Ma; | ||
for(l=0;l<20;l++) | ||
{X=X*Fi+Ni;Y=Y*Fb+Mb;if(((X*Ff+Nf)%(Y*Fc+Mc))!=0)break; | ||
} | ||
if(l==20){s=sb((X*Ff+Nf)/(Y*Fc+Mc));ss=""; | ||
cerr<<"\n"<<sb(Y*Fc+Mc)<<"*"<<s<<" = "<<sb(X*Ff+Nf); | ||
for(i=0;i<=m;i++){polyn[i]=0;polfact1[i]=0;polfact2[i]=0;} | ||
polyn[m]=Ndd*Ff*(b-1)*(b-1)+d*Ff*(b-1); | ||
polyn[0]=Nf*(b-1)*(b-1)-d*Ff*(b-1); | ||
polfact1[h]=Ma*Fc*(b-1)+dd*Fc; | ||
polfact1[0]=Mc*(b-1)-dd*Fc;L2=1;j=0; | ||
for(i=s.length()-1;i>=0;i--) | ||
{for(k=1;(k<=19)&&(i>=k);k++)if(s[i-k]!=s[i])break; | ||
if(k<=19){if(k>=15){polfact2[j]=polfact2[j]-w[s[i]]*L2; | ||
sss=s[i];sss="{"+sss+"}";i=i-k+1; | ||
for(k=k;k<=19;k++){sss=sss+'-';L2=L2/b;} | ||
for(k=0;k<decal;k++)sss=sss+'-'; | ||
ss=sss+ss; | ||
j++;polfact2[j]=w[s[i]]*L2; | ||
} | ||
else {ss=s[i]+ss; | ||
polfact2[j]=polfact2[j]+w[s[i]]*(b-1)*L2;L2=L2*b; | ||
} | ||
} | ||
else{sss=s[i];sss="{"+sss;sss=sss+'}'; | ||
for(k=0;k<decal;k++)sss=sss+'-'; | ||
ss=sss+ss; | ||
polfact2[j]=polfact2[j]-w[s[i]]*L2; | ||
j++;polfact2[j]=w[s[i]]*L2;i=i-19; | ||
} | ||
} | ||
for(k=i;k>=0;k--){ss=s[k]+ss; | ||
polfact2[j]=polfact2[j]+w[s[k]]*(b-1)*L2; | ||
L2=L2*b; | ||
} | ||
for(i=0;i<=m;i++){X=polyn[i];for(j=0;j<=i;j++) | ||
X=X-polfact1[j]*polfact2[i-j]; | ||
if(X!=0){cerr<<"\n%%% : "; | ||
for(j=0;j<=m;j++)cerr<<polyn[m-j]<<','; | ||
cerr<<"\n : "; | ||
for(j=0;j<=m;j++)cerr<<polfact1[m-j]<<','; | ||
cerr<<"\n : "; | ||
for(j=0;j<=m;j++)cerr<<polfact2[m-j]<<','; | ||
break; | ||
} | ||
} | ||
ss=sb(Mc)+"]*["+ss+']';for(decal=decal;decal>0;decal--)ss='-'+ss; | ||
return ('['+sb(Ma)+'{'+sb0(Mb)+'}'+ss); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
N1=Ndd*Ff+Nf;if(m>=4) | ||
for(i=0;i<factors.size();i++) | ||
{s=sb(factors[i]);ss=sb(N1/factors[i]); | ||
for(j=0;j<=s.length();j++) | ||
{Ma=0;for(k=0;k<j;k++)Ma=Ma*b+w[s[k]]; | ||
for(jj=j;jj<=s.length();jj++) | ||
{Maa=0;Faa=1;for(k=j;k<jj;k++){Maa=Maa*b+w[s[k]];Faa=Faa*b;} | ||
Mc=0;Fc=1; | ||
for(k=jj;k<s.length();k++){Fc=Fc*b;Mc=Mc*b+w[s[k]];} | ||
for(dd=0;dd<b;dd++){if((dd==0)&&(j==0))continue;for(ddd=0;ddd<b;ddd++) | ||
{Mb=0;Fb=1;Mbb=0;Fbb=1; | ||
//for(h=1;h<m;h++) | ||
{Mb=Mb*b+dd;Fb=Fb*b;Mbb=Mbb*b+ddd;Fbb=Fbb*b;X=Ndd;Y=Ma;Z=Maa;FZ=Faa; | ||
for(l=0;l<20;l++) | ||
{X=X*Fi+Ni;Y=Y*Fb+Mb;Z=Z*Fbb+Mbb;FZ=FZ*Fbb; | ||
if(((X*Ff+Nf)%((Y*FZ+Z)*Fc+Mc))!=0)break;} | ||
if(l==20){s=sb((X*Ff+Nf)/((Y*FZ+Z)*Fc+Mc));ss="";cerr<<"\n$ : "<<sb(Fi); | ||
cerr<<"\n"<<sb((Y*FZ+Z)*Fc+Mc)<<"*"<<s<<" = "<<sb(X*Ff+Nf); | ||
for(i=0;i<=m;i++){polyn[i]=0;polfact1[i]=0;polfact2[i]=0;} | ||
polyn[m]=Ndd*Ff*(b-1)*(b-1)+d*Ff*(b-1); | ||
polyn[0]=Nf*(b-1)*(b-1)-d*Ff*(b-1); | ||
polfact1[h]=Ma*Fc*(b-1)+dd*Fc; //à adapter | ||
polfact1[0]=Mc*(b-1)-dd*Fc;L2=1;j=0; | ||
for(i=s.length()-1;i>=19;i--) | ||
{for(k=1;k<=19;k++)if(s[i-k]!=s[i])break; | ||
if(k<=19){if(k>=15){polfact2[j]=polfact2[j]-w[s[i]]*L2; | ||
sss=s[i];sss="{"+sss+"}";i=i-k+1; | ||
for(k=k;k<=19;k++){sss=sss+'-';L2=L2/b;} | ||
ss=sss+ss; | ||
j++;polfact2[j]=w[s[i]]*L2; | ||
} | ||
else {ss=s[i]+ss; | ||
polfact2[j]=polfact2[j]+w[s[i]]*(b-1)*L2;L2=L2*b; | ||
} | ||
} | ||
else{sss=s[i];sss="{"+sss;ss=sss+'}'+ss; | ||
polfact2[j]=polfact2[j]-w[s[i]]*L2; | ||
j++;polfact2[j]=w[s[i]]*L2;i=i-19; | ||
} | ||
} | ||
for(k=i;k>=0;k--){ss=s[k]+ss; | ||
polfact2[j]=polfact2[j]+w[s[k]]*(b-1)*L2; | ||
L2=L2*b; | ||
} | ||
for(i=0;i<=m;i++){X=polyn[i];for(j=0;j<=i;j++) | ||
X=X-polfact1[j]*polfact2[i-j]; | ||
if(X!=0){cerr<<"\n%%% : "; | ||
for(j=0;j<=m;j++)cerr<<polyn[m-j]<<','; | ||
cerr<<"\n : "; | ||
for(j=0;j<=m;j++)cerr<<polfact1[m-j]<<','; | ||
cerr<<"\n : "; | ||
for(j=0;j<=m;j++)cerr<<polfact2[m-j]<<','; | ||
break; | ||
} | ||
} | ||
return ('['+sb(Ma)+'{'+sb0(Mb)+'}'+sb(Maa)+'{'+sb0(Mbb)+'}'+sb(Mc)+"]*["+ss+']'); | ||
} | ||
} | ||
}} | ||
} | ||
} | ||
} | ||
} | ||
Ndd=Ndd*Fi+Ni; | ||
} | ||
return ""; | ||
} | ||
bool ok(long int n) // is prime? | ||
{unsigned int kk; | ||
if (n<2) return false; | ||
for (kk=2;kk*kk<=n;kk++) | ||
{if(n % kk==0)return false;} | ||
return true; | ||
} | ||
|
||
main(int argc, char *argv[]) | ||
{string ms,pref,prefms,p; | ||
ms=argv[1];b=atoi(argv[1]); | ||
for(i=2;i<b*b*b*b;i++)if(ok(i))fact.push_back(i); | ||
k=2;while(k<bound){NN=k;if(prime(NN))prm.push_back(k);k++;} | ||
for(char c='0';c<='9';c++){w[c]=0+c-'0';tr[0+c-'0']=c;} | ||
for(char c='A';c<='Z';c++){w[c]=10+c-'A';tr[10+c-'A']=c;} | ||
for(char c='a';c<='z';c++){w[c]=36+c-'a';tr[36+c-'a']=c;} | ||
while(cin>>p) | ||
{//if(p[0]=='{')p=p[1]+p;if(p[p.length()-1]=='}')p=p+p[p.length()-2]; | ||
cerr<<"\n"<<p; | ||
NN=0;for(i1=0;p[i1]!='{';i1++)NN=NN*b+w[p[i1]];d=w[p[i1+1]]; | ||
Nf=0;Ff=1;for(i1=i1+3;i1<p.length();i1++){Ff=Ff*b;Nf=Nf*b+w[p[i1]];} | ||
Ni=0;Fi=1; | ||
for(i=0;i<=cyclemax;i++)for(j=0;j<cyclemax;j++)divfound[i][j]=""; | ||
for(m=1;m<=cyclemax;m++) | ||
{Ni=Ni*b+d;Fi=Fi*b;Nd=NN; | ||
for(r=0;r<m;r++) | ||
{if(divfound[m][r]=="") | ||
{divfound[m][r]=check0(); | ||
if(divfound[m][r]!="") | ||
{cerr<<"\ndiv "<<divfound[m][r]<<" pour i="<<r<<" mod("<<m<<")"; | ||
for(j=2;(j*m)<=cyclemax;j++) | ||
for(k=0;k<j;k++) | ||
if(divfound[j*m][r+k*m]=="")divfound[j*m][r+k*m]=divfound[m][r]; | ||
for(i=0;i<m;i++)if(divfound[m][i]=="")break; | ||
if(i==m){cerr<<"\n"<<p<<" => cycle de taille "<<m<<" : "; | ||
for(i=0;i<m;i++)cerr<<divfound[m][i]<<',';break; | ||
} | ||
} | ||
} | ||
Nd=Nd*b+d; | ||
} | ||
if(r!=m)break; | ||
} | ||
if(m>cyclemax)cout<<p<<"\n"; | ||
cerr<<"\n===================================\n"; | ||
} | ||
} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <vector> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include <stdlib.h> | ||
|
||
#include "big.h" /* include MIRACL system */ | ||
|
||
#define cyclemax 12 | ||
#define bound 1000000 | ||
|
||
using namespace std; | ||
|
||
Miracl precision(20000,100); /* bigs are 20000 decimal digits long */ | ||
|
||
int b,ite,n1,n2,i,j,k,h,l,m,r,i1,i2,d,dd; char c; string s,ss,sss; | ||
vector <int> fact;vector <int> prm; | ||
int w[128];int f[128]; | ||
string divfound[cyclemax+1][cyclemax+1]; | ||
Big polyn[100], polfact1[100], polfact2[100]; | ||
Big NN,Nd,Ni,Fi,Ib,Nf,Ff,N1,MM,Fb,Fc,Ma,Mb,Mc,X,Y,L2; | ||
vector <Big> factors; | ||
|
||
string sb(Big x) | ||
{Big y=x; Big br; int r; string s=""; char c; | ||
while (y!=0){br=y%b;y=y/b; | ||
for(r=0;r<36;r++)if(br==r)break; | ||
if(r<10)c='0'+r; else c='A'+r-10; s=c+s;}return s; | ||
} | ||
string sb0(Big x) | ||
{Big y=x; Big br; int r; string s=""; char c; | ||
if(x==0)return "0"; | ||
while (y!=0){br=y%b;y=y/b; | ||
for(r=0;r<36;r++)if(br==r)break; | ||
if(r<10)c='0'+r; else c='A'+r-10; s=c+s;}return s; | ||
} | ||
string s10(Big x) | ||
{Big y=x; Big br; int r; string s=""; char c; | ||
if(x==0)return "0"; | ||
while (y!=0){br=y%10;y=y/10; | ||
for(r=0;r<10;r++)if(br==r)break;c='0'+r;s=c+s;}return s; | ||
} | ||
string check0() | ||
{for(ite=0;ite<fact.size();ite++) | ||
{i=fact[ite];n1=Nd%i;n2=(n1*Ff+Nf)%i; | ||
if((n2==0)&&(((n1*Fi+Ni)%i)==n1))break; | ||
} | ||
if(ite!=fact.size()){return sb(i);} | ||
N1=Nd*Ff+Nf; | ||
if(prime(N1)){cerr<<"\nnouveau premier trouvé:"<<sb(N1);return sb(N1);} | ||
j=0;MM=N1;factors.clear();factors.push_back(1); | ||
while((j<prm.size())&&(MM!=1))if((MM%prm[j])==0) | ||
{k=factors.size(); | ||
for(i=0;i<k;i++) | ||
{for(h=0;h<factors.size();h++)if(factors[h]==(factors[i]*prm[j]))break; | ||
if(h==factors.size())factors.push_back(factors[i]*prm[j]); | ||
} | ||
MM=MM/prm[j]; | ||
} | ||
else j++; | ||
for(i=0;i<factors.size();i++) | ||
{s=sb(factors[i]);ss=sb(N1/factors[i]); | ||
for(j=0;j<=s.length();j++) | ||
{Ma=0;for(k=0;k<j;k++)Ma=Ma*b+w[s[k]]; | ||
Mc=0;Fc=1; | ||
for(k=j;k<s.length();k++){Fc=Fc*b;Mc=Mc*b+w[s[k]];} | ||
for(dd=0;dd<b;dd++) | ||
{Mb=0;Fb=1;if((dd==0)&&(j==0))continue; | ||
for(h=1;h<m;h++) | ||
{Mb=Mb*b+dd;Fb=Fb*b;X=Nd;Y=Ma; | ||
for(l=0;l<20;l++) | ||
{X=X*Fi+Ni;Y=Y*Fb+Mb;if(((X*Ff+Nf)%(Y*Fc+Mc))!=0)break; | ||
} | ||
if(l==20){s=sb((X*Ff+Nf)/(Y*Fc+Mc));ss=""; | ||
cerr<<"\n"<<sb(Y*Fc+Mc)<<"*"<<s<<" = "<<sb(X*Ff+Nf); | ||
for(i=0;i<=m;i++){polyn[i]=0;polfact1[i]=0;polfact2[i]=0;} | ||
polyn[m]=Nd*Ff*(b-1)*(b-1)+d*Ff*(b-1); | ||
polyn[0]=Nf*(b-1)*(b-1)-d*Ff*(b-1); | ||
polfact1[h]=Ma*Fc*(b-1)+dd*Fc; | ||
polfact1[0]=Mc*(b-1)-dd*Fc;L2=1;j=0; | ||
for(i=s.length()-1;i>=19;i--) | ||
{for(k=1;k<=19;k++)if(s[i-k]!=s[i])break; | ||
if(k<=19){if(k>=15){polfact2[j]=polfact2[j]-w[s[i]]*L2; | ||
sss=s[i];sss="{"+sss+"}";i=i-k+1; | ||
for(k=k;k<=19;k++){sss=sss+'-';L2=L2/b;} | ||
ss=sss+ss; | ||
j++;polfact2[j]=w[s[i]]*L2; | ||
} | ||
else {ss=s[i]+ss; | ||
polfact2[j]=polfact2[j]+w[s[i]]*(b-1)*L2;L2=L2*b; | ||
} | ||
} | ||
else{sss=s[i];sss="{"+sss;ss=sss+'}'+ss; | ||
polfact2[j]=polfact2[j]-w[s[i]]*L2; | ||
j++;polfact2[j]=w[s[i]]*L2;i=i-19; | ||
} | ||
} | ||
for(k=i;k>=0;k--){ss=s[k]+ss; | ||
polfact2[j]=polfact2[j]+w[s[k]]*(b-1)*L2; | ||
L2=L2*b; | ||
} | ||
for(i=0;i<=m;i++){X=polyn[i];for(j=0;j<=i;j++) | ||
X=X-polfact1[j]*polfact2[i-j]; | ||
if(X!=0){for(j=0;j<=m;j++)cerr<<polyn[m-j]<<','; | ||
cerr<<"\n : "; | ||
for(j=0;j<=m;j++)cerr<<polfact1[m-j]<<','; | ||
cerr<<"\n : "; | ||
for(j=0;j<=m;j++)cerr<<polfact2[m-j]<<','; | ||
break; | ||
} | ||
} | ||
return ('['+sb(Ma)+'{'+sb0(Mb)+'}'+sb(Mc)+"]*["+ss+']'); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
for(i=0;i<b*b;i++) | ||
{for(j=0;j<b;j++) | ||
{if((i==0)&&(j==0))continue;Ma=i;Mb=j;Fb=b;Fc=1; | ||
for(k=0;k<3;k++) | ||
{for(h=0;h<Fc;h++) | ||
{Mc=h;X=Nd;Y=Ma;X=X*Fi+Ni;if((X*Ff+Nf)<=(Y*Fc+Mc))continue; | ||
for(l=0;l<20;l++) | ||
{X=X*Fi+Ni;Y=Y*Fb+Mb;if(((X*Ff+Nf)%(Y*Fc+Mc))!=0)break; | ||
} | ||
if(l==20)return ('['+sb(Ma)+'{'+sb0(Mb)+"}-"+sb(Mc)+']'); | ||
Mc=h;X=Nd;Y=Ma;X=X*Fi+Ni;X=X*Fi+Ni; | ||
for(l=0;l<20;l++) | ||
{X=X*Fi+Ni;Y=Y*Fb+Mb;if(((X*Ff+Nf)%(Y*Fc+Mc))!=0)break; | ||
} | ||
if(l==20)return ('['+sb(Ma)+'{'+sb0(Mb)+"}--"+sb(Mc)+']'); | ||
} | ||
Fc=Fc*b; | ||
} | ||
} | ||
} | ||
|
||
|
||
return ""; | ||
} | ||
bool ok(long int n) // is prime? | ||
{unsigned int kk; | ||
if (n<2) return false; | ||
for (kk=2;kk*kk<=n;kk++) | ||
{if(n % kk==0)return false;} | ||
return true; | ||
} | ||
|
||
main(int argc, char *argv[]) | ||
{string ms,pref,prefms,p; | ||
ms=argv[1];b=atoi(argv[1]); | ||
for(i=2;i<b*b*b*b;i++)if(ok(i))fact.push_back(i); | ||
k=2;while(k<bound){NN=k;if(prime(NN))prm.push_back(k);k++;} | ||
for(char c='0';c<='9';c++)w[c]=0+c-'0';for(char c='A';c<='Z';c++)w[c]=10+c-'A'; | ||
while(cin>>p) | ||
{if(p[0]=='{')p=p[1]+p;if(p[p.length()-1]=='}')p=p+p[p.length()-2];cerr<<"\n"<<p; | ||
NN=0;for(i1=0;p[i1]!='{';i1++)NN=NN*b+w[p[i1]];d=w[p[i1+1]]; | ||
Nf=0;Ff=1;for(i1=i1+3;i1<p.length();i1++){Ff=Ff*b;Nf=Nf*b+w[p[i1]];} | ||
Ni=0;Fi=1; | ||
for(i=0;i<=cyclemax;i++)for(j=0;j<cyclemax;j++)divfound[i][j]=""; | ||
for(m=1;m<=cyclemax;m++) | ||
{Ni=Ni*b+d;Fi=Fi*b;Nd=NN; | ||
for(r=0;r<m;r++) | ||
{if(divfound[m][r]=="") | ||
{divfound[m][r]=check0(); | ||
if(divfound[m][r]!="") | ||
{cerr<<"\ndiv "<<divfound[m][r]<<" pour i="<<r<<" mod("<<m<<")"; | ||
for(j=2;(j*m)<=cyclemax;j++) | ||
for(k=0;k<j;k++) | ||
if(divfound[j*m][r+k*m]=="")divfound[j*m][r+k*m]=divfound[m][r]; | ||
for(i=0;i<m;i++)if(divfound[m][i]=="")break; | ||
if(i==m){cerr<<"\ncycle de taille "<<m<<" : "; | ||
for(i=0;i<m;i++)cerr<<divfound[m][i]<<',';break; | ||
} | ||
} | ||
} | ||
Nd=Nd*b+d; | ||
} | ||
if(r!=m)break; | ||
} | ||
if(m>cyclemax)cout<<p<<"\n"; | ||
cerr<<"\n===================================\n"; | ||
} | ||
} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include <stdlib.h> | ||
using namespace std; | ||
|
||
struct elem{string mm;}; | ||
list<elem> found;elem el; | ||
|
||
ifstream kern; ofstream ckern; | ||
bool coverexact(string el2,string el1) | ||
{int i,j; | ||
i=0;j=0; | ||
while(i<el1.length()) | ||
{if(j==el2.length())return false; | ||
if(el1[i]==el2[j]){i++;j++;continue;} | ||
if(el1[i]=='{'){while(el2[j]==el1[i+1])j++;i=i+3;continue;} | ||
return false; | ||
} | ||
if(j==el2.length())return true;else return false; | ||
} | ||
|
||
main(int argc, char *argv[]) | ||
{string p,pp,ms,pref,prefms;int m,l,i,j; | ||
bool fin; | ||
list<string> foundM,found10; | ||
list<elem>::iterator it,itp; | ||
{ms=argv[1]; | ||
pref="kernel"; prefms=pref+ms; | ||
kern.open(prefms.c_str()); | ||
while(kern>>p){pp="";l=1;while(p[l]!='"'){pp=pp+p[l];l++;} | ||
el.mm=pp;found.push_back(el);} | ||
while(cin>>p) | ||
{l=0; | ||
while(p[l]!='{')l++; | ||
if(p[l+2]!='}'){cerr<<"ERREUR 0:"<<p<<"\n";break;}l=l+3; | ||
while(l<p.length())if(p[l]=='{'){cerr<<"ERREUR 1:"<<p<<"\n";break;}else l++; | ||
for(it=found.begin();it!=found.end();it++)if(coverexact((*it).mm,p))break; | ||
if(it==found.end())cerr<<p<<"\n"; else cout<<p<<"\n"; | ||
} | ||
kern.close(); | ||
}} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include <stdlib.h> | ||
using namespace std; | ||
|
||
ifstream result;int deploy;string p; | ||
|
||
string itos(int i) // convert int to string | ||
{stringstream s;s << i;return s.str();} | ||
|
||
string cvrt(char c) | ||
{if((c>='0')&&(c<='9')) return itos(c-'0'); else return itos(10+c-'A');} | ||
|
||
void printstringM(string sM,string s,string sr) | ||
{int i,ki;char c; | ||
for(i=0;i<sr.length();i++)if(sr[i]=='{')break; | ||
else{sM="("+sM+")*M+"+cvrt(sr[i]);s=s+sr[i];} | ||
if(i<sr.length())sr=sr.substr(i+1,sr.length()-i);else sr=""; | ||
if(sr.empty()){cout<<"x:="<<sM<<":\n"; | ||
cout<<"isprime(x),ifactor(x),"<<'"'<<p<<"->"<<s<<"="<<'"'<<",x;\n"; | ||
cout.flush();return;} | ||
c=sr[0];for(i=1;i<sr.length();i++)if(sr[i]=='}')break; | ||
sr=sr.substr(i+1,sr.length()-i); | ||
for(ki=0;ki<=deploy;ki++) | ||
{printstringM(sM,s,sr); | ||
s=s+c; | ||
sM="("+sM+")*M+"+cvrt(c); | ||
} | ||
} | ||
|
||
main(int argc, char *argv[]) | ||
{string ms,pref,prefms;int m,k,l,n;char c; | ||
for(k=1;k<argc-1;k++) | ||
{ms=argv[k];m=atoi(argv[k]);deploy=atoi(argv[argc-1]); | ||
pref="res"; prefms=pref+ms; | ||
result.open(prefms.c_str()); | ||
pref="resM"; prefms=pref+ms; | ||
cout<<"M:="<<m<<":\n"; | ||
while(result>>p)if(p[0]=='%')break; | ||
while(result>>p)if(p[0]=='%')break; else | ||
{n=0;for(l=p.length()-1;l>=0;l--)if(p[l]=='{'){n++;c=p[l+1];while(c==p[l-1]){p.erase(l-1,1);l--;}} | ||
if(n>0){printstringM("0","",p);} | ||
} | ||
result.close();} | ||
} // fin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
using namespace std; | ||
|
||
main(int argc, char *argv[]) | ||
{string p,ms,pref,prefms,mm,m10,mM,md;int m,k,nn,l,i,j; | ||
list<string> foundM,found10; | ||
while(cin>>p)if(p=="true,") | ||
{cin>>p;i=0; | ||
while (p[i]!='>')if(i==p.length()){cin>>p;i=0;} | ||
else i++; | ||
mm="";m10="";i++; | ||
while (p[i]!='=')if(i==p.length()){cin>>p;i=0;} | ||
else if(p[i]==' '){i++;} | ||
else if(p[i]=='\\'){i++;} | ||
else {mm=mm+p[i];i++;}i++; | ||
while (p[i]!=',')if(i==p.length()){cin>>p;i=0;} | ||
else i++;i++; | ||
while (true)if(i==p.length()){cin>>p;i=0;} | ||
else if(p[i]==' '){i++;} | ||
else if(p[i]=='\\'){i++;} | ||
else if((p[i]<'0')||(p[i]>'9'))break; | ||
else {m10=m10+p[i];i++;} | ||
cout<<'"'<<mm<<'"'<<'='<<m10<<",\n"; | ||
}} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
using namespace std; | ||
|
||
|
||
main(int argc, char *argv[]) | ||
{int m,k,deploy,pp,ss,cc,l,i,j;string p,s,ms,fam,famms,prefms; char c; | ||
ifstream families; | ||
for(k=1;k<argc-1;k++) | ||
{ms=argv[k];m=atoi(argv[k]);deploy=atoi(argv[argc-1]); | ||
fam="fam"; famms=fam+ms; | ||
families.open(famms.c_str()); | ||
while(families>>p>>c>>s) | ||
{cout<<'"'<<"m="+ms+": "+p+"{"+c+"}"+s+'"'+";\n"; | ||
pp=0; | ||
for(i=0;i<p.length();i++) | ||
{if((p[i]>='0')&&(p[i]<='9')) j=p[i]-'0'; else j=10+p[i]-'A'; | ||
pp=pp*m+j;} | ||
ss=0; | ||
for(i=0;i<s.length();i++) | ||
{if((s[i]>='0')&&(s[i]<='9')) j=s[i]-'0'; else j=10+s[i]-'A'; | ||
ss=ss*m+j;} | ||
if((c>='0')&&(c<='9')) cc=c-'0'; else cc=10+c-'A'; | ||
cout<<"x:="<<pp<<":\n"; | ||
for(i=0;i<=deploy;i++) | ||
{cout<<"xx:=x*"<<m<<"^"<<s.length()<<"+"<<ss<< | ||
":x:=x*"<<m<<"+"<<cc<<":\n"; | ||
cout<<"["<<i<<",isprime(xx)"; | ||
if(i<20)cout<<",ifactor(xx)];"; else cout<<"];"; | ||
} | ||
// cout<<"xx;\n"; | ||
} | ||
families.close();} | ||
} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
using namespace std; | ||
|
||
|
||
main(int argc, char *argv[]) | ||
{int m,k,pp,ss,cc,l,i,j;string p,s; char c; | ||
m=atoi(argv[1]);k=atoi(argv[2]); | ||
p=argv[3];c=argv[4][0];s=argv[5]; | ||
pp=0; | ||
for(i=0;i<p.length();i++) | ||
{if((p[i]>='0')&&(p[i]<='9')) j=p[i]-'0'; else j=10+p[i]-'A'; | ||
pp=pp*m+j;} | ||
ss=0; | ||
for(i=0;i<s.length();i++) | ||
{if((s[i]>='0')&&(s[i]<='9')) j=s[i]-'0'; else j=10+s[i]-'A'; | ||
ss=ss*m+j;} | ||
if((c>='0')&&(c<='9')) cc=c-'0'; else cc=10+c-'A'; | ||
cout<<"x:="<<pp<<":\n"; | ||
for(i=0;i<=k;i++) | ||
{cout<<"xx:=x*"<<m<<"^"<<s.length()<<"+"<<ss<< | ||
";x:=x*"<<m<<"+"<<cc<<":\n"; | ||
cout<<i<<";ifactor(xx);\n"; | ||
} | ||
// cout<<"xx;\n"; | ||
} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
using namespace std; | ||
|
||
ifstream kern; | ||
bool cover(string el1,string el2) | ||
{int i,j,k; | ||
if(el1.length()==el2.length())return false; | ||
if(el1.length()>el2.length())return(false); | ||
i=0;j=0; | ||
while(i<el1.length()) | ||
{if(el1[i]==el2[j]) | ||
{i++;j++;if(i==el1.length())return true;if(j>=el2.length())return false;} | ||
else{j++;if(j>=el2.length())return false;} | ||
} | ||
return true; | ||
} | ||
int order(string el1,string el2) | ||
{int i; | ||
if(el1.length()>el2.length())return 1; | ||
if(el1.length()<el2.length())return 2; | ||
i=0; | ||
while(i<el1.length()) | ||
{if(el1[i]==el2[i])i++; | ||
else if(el1[i]<el2[i])return 2; | ||
else return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
string itos(int i) // convert int to string | ||
{stringstream s;s << i;return s.str();} | ||
|
||
string cvrt(char c) | ||
{if((c>='0')&&(c<='9')) return itos(c-'0'); else return itos(10+c-'A');} | ||
|
||
main(int argc, char *argv[]) | ||
{string p,ms,pref,prefms,mm,m10,mM,md;int m,k,nn,l,i,j; | ||
bool fin; | ||
list<string> foundM,found10; | ||
list<string>::iterator itM,it10,fitM,fit10; | ||
for(k=1;k<argc;k++) | ||
{ms=argv[k];m=atoi(argv[k]); | ||
pref="kernel"; prefms=pref+ms; | ||
kern.open(prefms.c_str()); | ||
cout<<"M:="<<ms<<":\n";nn=0; | ||
while(kern>>p) | ||
{nn++;l=p.length(); | ||
if(p[0]!='"'){cerr<<"problème de quote à la ligne"<<nn; } | ||
if(p[l-1]!=','){cerr<<"problème de , à la ligne"<<nn; } | ||
for(i=1;i<l;i++)if(p[i]=='"') | ||
{mm=p.substr(1,i-1);m10=p.substr(i+2,l-i-3);break;} | ||
if((nn>1)&&(order(found10.back(),m10)!=2)) | ||
{cerr<<"problème d'ordre à la ligne"<<nn; | ||
itM=foundM.begin();it10=found10.begin(); | ||
while(order(*it10,m10)==2){it10++;itM++;} | ||
if(order(*it10,m10)==1){foundM.insert(itM,mm);found10.insert(it10,m10);} | ||
} | ||
else{foundM.push_back(mm);found10.push_back(m10);} | ||
} | ||
nn==0; | ||
it10=found10.begin();itM=foundM.begin(); | ||
while(itM!=foundM.end()) | ||
{fitM=itM;fit10=it10;fitM++;fit10++; | ||
while(fitM!=foundM.end()) | ||
{if(cover(*itM,*fitM)) | ||
{cerr<<*itM<<" domine "<<*fitM<<"\n"; | ||
fitM=foundM.erase(fitM);fit10=found10.erase(fit10);} | ||
else{fitM++;fit10++;} | ||
} | ||
itM++;it10++; | ||
} | ||
itM=foundM.begin();it10=found10.begin(); | ||
cerr<<"taille des listes: "<<foundM.size()<<","<<found10.size()<<"\n"; | ||
it10=found10.begin();itM=foundM.begin(); | ||
while(itM!=foundM.end()) | ||
{mM="0";for(i=0;i<(*itM).length();i++){mM="("+mM+")*M+"+cvrt((*itM)[i]);} md=*it10; | ||
cout<<"[testeq("<<mM<<","<<md<<"),isprime("<<mM<<"),"<<mM<<","<<md<<"];\n"; | ||
itM++;it10++; | ||
} | ||
|
||
kern.close(); | ||
}} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//a partir d'un fichier de familles infinies, creer des familles lineaires | ||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include <stdlib.h> | ||
using namespace std; | ||
|
||
struct elem{string mm;}; | ||
list<elem> found;elem el; | ||
struct li{int lst[5];}; | ||
|
||
ifstream kern; ofstream ckern; | ||
|
||
main(int argc, char *argv[]) | ||
{string p,pp,ms,pref,prefms;int i,ii,j,jj,l,m,n,k; | ||
bool fin; | ||
list<string> foundM,found10; | ||
list<elem>::iterator it,itp; | ||
string sig[5];char d[5];li rp; | ||
list<li> listrep; list<li>::iterator itl,itm; | ||
{ms=argv[1]; | ||
pref="kernel"; prefms=pref+ms; | ||
kern.open(prefms.c_str()); | ||
m=atoi(argv[2]); | ||
while(kern>>p){pp="";l=1;while(p[l]!='"'){pp=pp+p[l];l++;} | ||
el.mm=pp;found.push_back(el);} | ||
while(cin>>p) | ||
{n=0;sig[0]="";listrep.clear();//cerr<<p<<"=>\n"; | ||
for(i=0;i<p.length();i++) | ||
{if(p[i]!='{'){sig[n]=sig[n]+p[i]; } else | ||
{if(p[i+2]!='}'){cerr<<p<<"\n";break;} else | ||
{n++;sig[n]="";d[n]=p[i+1];i=i+2;} | ||
} | ||
} | ||
if(n<=1){cout<<p<<"\n";continue;} | ||
for(it=found.begin();it!=found.end();it++) | ||
{ii=0;for(i=0;i<sig[0].length();i++)if((*it).mm[ii]==sig[0][i])ii++; | ||
for(j=1;j<=n;j++) | ||
{rp.lst[j]=0;while((*it).mm[ii]==d[j]){rp.lst[j]++;ii++;} | ||
if(rp.lst[j]>m)break; | ||
for(i=0;i<sig[j].length();i++)if((*it).mm[ii]==sig[j][i])ii++; | ||
}if(ii<(*it).mm.length())continue; | ||
else {listrep.push_back(rp);//cerr<<(*it).mm<<"\n"; | ||
} | ||
} | ||
if(listrep.empty()){cerr<<p<<"\n";continue;} | ||
for(i=1;i<=n;i++) | ||
{itm=listrep.begin();itl=itm; | ||
for(itl++; itl!=listrep.end(); itl++) if((*itl).lst[i]<(*itm).lst[i])itm=itl; | ||
for(j=0;j<=(*itm).lst[i];j++) | ||
{cout<<sig[0];for(ii=1;ii<i;ii++)cout<<"{"<<d[ii]<<"}"<<sig[ii]; | ||
for(k=0;k<j;k++)cout<<d[i];cout<<sig[i]; | ||
for(ii=i+1;ii<=n;ii++)cout<<"{"<<d[ii]<<"}"<<sig[ii];cout<<"\n"; | ||
} | ||
} | ||
} | ||
kern.close(); | ||
}} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <vector> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <stdlib.h> | ||
#include "big.h" /* include MIRACL system */ | ||
|
||
using namespace std; | ||
|
||
Miracl precision(5000,100); /* bigs are 5000 centimal digits long */ | ||
|
||
unsigned int pgcd(unsigned long int i, unsigned long int j) | ||
{unsigned long int ii,jj,kk; if(i==0)return j; | ||
if(j>i){ii=j;jj=i;} else {ii=i;jj=j;} | ||
while(jj!=0){kk=ii%jj;ii=jj;jj=kk;} | ||
return ii;} | ||
unsigned int min(unsigned int i, unsigned int j) | ||
{if(i<=j)return i;else return j;} | ||
bool ok(long int n) // is prime? | ||
{unsigned int kk; | ||
if (n<2) return false; | ||
for (kk=2;kk*kk<=n;kk++) | ||
{if(n % kk==0)return false;} | ||
return true; | ||
} | ||
|
||
short int si,i,il,ir,j,ii,b,ilb,ilh,irb,irh; | ||
main(int argc, char *argv[]) | ||
{string ms,pref,prefms; | ||
ms=argv[1];b=atoi(argv[1]); | ||
ilb=1;ilh=b;irb=1;irh=b; | ||
cout<<"pour la base "<<b<<", les premiers chiffres sont: "; | ||
for(il=ilb;il<ilh;il++)if(!ok(il))cout<<il<<", "; | ||
cout<<"\net les derniers chiffres sont: "; | ||
for(ir=irb;ir<irh;ir++)if(!ok(ir))if(pgcd(ir,b)==1)cout<<ir<<", ";cout<<"\n"; | ||
|
||
} // fin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
//a partir d'un fichier de familles infinies, creer des familles raffinées, en fonction du kernel actuel | ||
#include <vector> | ||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include <stdlib.h> | ||
#include "big.h" /* include MIRACL system */ | ||
using namespace std; | ||
|
||
Miracl precision(20000,128); /* bigs are 20000 centimal digits long */ | ||
|
||
vector<string> found; vector<int> point; vector <int> fact; | ||
char tr[128]; int w[128]; | ||
int b,m; | ||
|
||
string s10(Big x) | ||
{Big y=x; int r; string s=""; | ||
while (y!=0){r=y%10;y=y/10;s=tr[r]+s;} | ||
return s; | ||
} | ||
|
||
bool ok(long int n) // is prime? | ||
{unsigned int kk; | ||
if (n<2) return false; | ||
for (kk=2;kk*kk<=n;kk++) | ||
{if(n % kk==0)return false;} | ||
return true; | ||
} | ||
|
||
int petit_facteur(string ss) | ||
{int i,i1,i2,ite;Big n1; | ||
for(ite=0;ite<fact.size();ite++) | ||
{i=fact[ite];i1=0;n1=0; | ||
while(i1<ss.length()) | ||
{for(i2=i1;i2<ss.length();i2++)if(ss[i2]=='{')break;else n1=n1*b+w[ss[i2]]; | ||
if(i2== ss.length()){if((n1%i)==0)return i;else break;} | ||
else{n1=n1%i;for(i2++;ss[i2]!='}';i2++){if(n1!=((n1*b+w[ss[i2]])%i))break;} | ||
if(ss[i2]!='}')break;}i1=i2+1; | ||
if(i1==ss.length())if(n1==0)return i; | ||
} | ||
}return 0; | ||
} | ||
|
||
void checkpat(string pat) | ||
{int i; bool test; Big n1; string ss; | ||
i=0;n1=0;test=false; | ||
while(i<pat.length()){if(pat[i]=='{'){test=true;while(pat[i]!='}')i++;i++;} | ||
else{n1=n1*b+w[pat[i]];ss=ss+pat[i];i++;}} | ||
if(prime(n1)) {cout<<'"'<<ss<<'"'<<'='<<s10(n1)<<",\n";return;} | ||
if(!test){cerr<<pat<<" n'est pas premier\n";return;} | ||
if(petit_facteur(pat)>0){cerr<<pat<<" a un facteur "<<petit_facteur(pat)<<"\n";return;} | ||
cout<<pat<<"\n"; | ||
} | ||
|
||
void printres(vector<int>point,string past,string pat) | ||
{int ipat=0,l,i,ipatp; bool test=false; char c; string loop,forw; vector<int>pointf; | ||
pointf.clear();for(l=0;l<found.size();l++)pointf.push_back(point[l]);ipatp=0; | ||
while(ipatp<pat.size())if(pat[ipatp]!='{') | ||
{for(l=0;l<found.size();l++)if(found[l][pointf[l]]==pat[ipatp]) | ||
{pointf[l]++;if(found[l][pointf[l]]=='"'){ | ||
//cerr<<" #"<<l<<','<<point[l]<<','<<pointf[l]<<'\n'; | ||
return;}}ipatp++;} | ||
else{while(pat[ipatp]!='}')ipatp++;ipatp++;} | ||
//cerr<<'?'<<past<<'+'<<pat<<'\n';for(l=0;l<found.size();l++)cerr<<' '<<point[l];cerr<<'\n'; | ||
if(petit_facteur(past+pat)>0){cerr<<past+pat<<" a un facteur "<<petit_facteur(past+pat)<<"\n";return;} | ||
if((past.size()+pat.size())>m){cout<<past+pat<<'\n';return;} | ||
while(ipat<pat.size()) | ||
{if(pat[ipat]!='{') | ||
{c=pat[ipat];for(l=0;l<found.size();l++){if(found[l][point[l]]==c){point[l]++;if(found[l][point[l]]=='"')return;}} | ||
past=past+pat[ipat];ipat++; | ||
} | ||
else | ||
{for(ipatp=ipat+1;pat[ipatp]!='}';ipatp++) | ||
{c=pat[ipatp];for(l=0;l<found.size();l++)if((found[l][point[l]])==c)break; | ||
if(l<found.size())forw.push_back(c); else loop.push_back(c);} | ||
if(!loop.empty()){past=past+'{'+loop+'}';} | ||
printres(point,past,pat.substr(ipatp+1,pat.size())); | ||
for(i=0;i<forw.size();i++){printres(point,past,forw[i]+pat.substr(ipat,pat.size()));} | ||
return; | ||
} | ||
}checkpat(past); | ||
} | ||
|
||
ifstream kern; | ||
|
||
main(int argc, char *argv[]) | ||
{string p,pat,pp,ms,pref,prefms; | ||
int ip,ipat,ipatp,l,i; | ||
|
||
ms=argv[1]; | ||
pref="kernel"; prefms=pref+ms;b=atoi(argv[1]); | ||
kern.open(prefms.c_str()); | ||
for(char c='0';c<='9';c++){w[c]=0+c-'0';tr[0+c-'0']=c;} | ||
for(char c='A';c<='Z';c++){w[c]=10+c-'A';tr[10+c-'A']=c;} | ||
for(char c='a';c<='z';c++){w[c]=36+c-'a';tr[36+c-'a']=c;} | ||
for(i=2;i<b*b;i++)if(ok(i))fact.push_back(i); | ||
if(argc>2)m=atoi(argv[2]); else m=100000; | ||
while(cin>>pat) | ||
{cerr<<pat<<" keeps "<<"\n"; | ||
found.clear();point.clear(); | ||
while(kern>>p) | ||
{ip=1;ipat=0; | ||
while(ipat<pat.size()) | ||
{if(pat[ipat]!='{'){if(p[ip]==pat[ipat]){ip++;ipat++;if(p[ip]=='"')break;}else ipat++;} | ||
else{ipatp=ipat+1;while(pat[ipatp]!='}') {if(p[ip]==pat[ipatp]) {ip++;break;} else ipatp++;} | ||
if(pat[ipatp]=='}')ipat=ipatp+1; | ||
} | ||
} | ||
if(p[ip]=='"'){ pp="";l=0;while(p[l]!='='){pp=pp+p[l];l++;} found.push_back(pp); point.push_back(1); cerr<<pp<<"\n";} | ||
} | ||
printres(point,"",pat); | ||
kern.clear();kern.seekg(0,ios::beg); | ||
} | ||
//kern.close(); | ||
} // fin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
//a partir d'un fichier de familles infinies, creer des familles raffinées, en fonction du kernel actuel | ||
#include <vector> | ||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
#include <stdlib.h> | ||
#include "big.h" /* include MIRACL system */ | ||
using namespace std; | ||
|
||
Miracl precision(20000,128); /* bigs are 20000 centimal digits long */ | ||
|
||
vector<string> found; vector<int> pointl,pointr; vector <int> fact; | ||
char tr[128]; int w[128]; | ||
int b,m; | ||
|
||
string s10(Big x) | ||
{Big y=x; int r; string s=""; | ||
while (y!=0){r=y%10;y=y/10;s=tr[r]+s;} | ||
return s; | ||
} | ||
|
||
bool ok(long int n) // is prime? | ||
{unsigned int kk; | ||
if (n<2) return false; | ||
for (kk=2;kk*kk<=n;kk++) | ||
{if(n % kk==0)return false;} | ||
return true; | ||
} | ||
|
||
int petit_facteur(string ss) | ||
{int i,i1,i2,ite;Big n1; | ||
for(ite=0;ite<fact.size();ite++) | ||
{i=fact[ite];i1=0;n1=0; | ||
while(i1<ss.length()) | ||
{for(i2=i1;i2<ss.length();i2++)if(ss[i2]=='{')break;else n1=n1*b+w[ss[i2]]; | ||
if(i2== ss.length()){if((n1%i)==0)return i;else break;} | ||
else{n1=n1%i;for(i2++;ss[i2]!='}';i2++){if(n1!=((n1*b+w[ss[i2]])%i))break;} | ||
if(ss[i2]!='}')break;}i1=i2+1; | ||
if(i1==ss.length())if(n1==0)return i; | ||
} | ||
}return 0; | ||
} | ||
|
||
void checkpat(string pat) | ||
{int i; bool test; Big n1; string ss; | ||
i=0;n1=0;test=false; | ||
while(i<pat.length()){if(pat[i]=='{'){test=true;while(pat[i]!='}')i++;i++;} | ||
else{n1=n1*b+w[pat[i]];ss=ss+pat[i];i++;}} | ||
if(prime(n1)) {cout<<'"'<<ss<<'"'<<'='<<s10(n1)<<",\n";return;} | ||
if(!test){cerr<<pat<<" n'est pas premier\n";return;} | ||
if(petit_facteur(pat)>0){cerr<<pat<<" a un facteur "<<petit_facteur(pat)<<"\n";return;} | ||
cout<<pat<<"\n"; | ||
} | ||
|
||
void printresr(vector<int>pointl,string pastl,string pat,vector<int>pointr,string pastr); | ||
|
||
void printresl(vector<int>pointl,string pastl,string pat,vector<int>pointr,string pastr) | ||
{int ipat=0,l,i,ipatp; bool test=false; char c; string loop,forw; vector<int>pointf; | ||
//cerr<<'?'<<pastl<<'+'<<pat<<'+'<<pastr<<"\n";for(l=0;l<found.size();l++)cerr<<';'<<pointl[l]<<','<<pointr[l]<<"\n"; | ||
pointf.clear();for(l=0;l<found.size();l++)pointf.push_back(pointl[l]);ipatp=0; | ||
while(ipatp<pat.size())if(pat[ipatp]!='{') | ||
{for(l=0;l<found.size();l++)if(found[l][pointf[l]]==pat[ipatp]) | ||
{pointf[l]++;if(pointf[l]>pointr[l]){return;}}ipatp++;} | ||
else{while(pat[ipatp]!='}')ipatp++;ipatp++;} | ||
if(petit_facteur(pastl+pat+pastr)>0){cerr<<pastl+pat+pastr<<" a un facteur "<<petit_facteur(pastl+pat+pastr)<<"\n";return;} | ||
if((pastl.size()+pat.size()+pastr.size())>m){cout<<pastl+pat+pastr<<'\n';return;} | ||
while(ipat<pat.size()) | ||
{if(pat[ipat]!='{') | ||
{c=pat[ipat];for(l=0;l<found.size();l++){if(found[l][pointl[l]]==c){pointl[l]++;if(pointl[l]>pointr[l])break;}} | ||
if(l<found.size())return;pastl=pastl+c;ipat++; | ||
} | ||
else | ||
{for(ipatp=ipat+1;pat[ipatp]!='}';ipatp++) | ||
{c=pat[ipatp];for(l=0;l<found.size();l++)if((found[l][pointl[l]])==c)break; | ||
if(l<found.size())forw.push_back(c); else loop.push_back(c);} | ||
if(!loop.empty()){pastl=pastl+'{'+loop+'}';} | ||
printresr(pointl,pastl,pat.substr(ipatp+1,pat.size()),pointr,pastr); | ||
for(i=0;i<forw.size();i++){ | ||
printresr(pointl,pastl,forw[i]+pat.substr(ipat,pat.size()),pointr,pastr);} | ||
return; | ||
} | ||
}checkpat(pastl+pastr); | ||
} | ||
|
||
void printresr(vector<int>pointl,string pastl,string pat,vector<int>pointr,string pastr) | ||
{int ipat=pat.size()-1,l,i,ipatp; bool test=false; char c; string loop,forw; vector<int>pointf; | ||
//cerr<<'!'<<pastl<<'+'<<pat<<'+'<<pastr<<"\n";for(l=0;l<found.size();l++)cerr<<';'<<pointl[l]<<','<<pointr[l]<<"\n"; | ||
pointf.clear();for(l=0;l<found.size();l++)pointf.push_back(pointl[l]);ipatp=0; | ||
while(ipatp<pat.size())if(pat[ipatp]!='{') | ||
{for(l=0;l<found.size();l++)if(found[l][pointf[l]]==pat[ipatp]) | ||
{pointf[l]++;if(pointf[l]>pointr[l]){return;}}ipatp++;} | ||
else{while(pat[ipatp]!='}')ipatp++;ipatp++;} | ||
if(petit_facteur(pastl+pat+pastr)>0){cerr<<pastl+pat+pastr<<" a un facteur "<<petit_facteur(pastl+pat+pastr)<<"\n";return;} | ||
if((pastl.size()+pat.size()+pastr.size())>m){cout<<pastl+pat+pastr<<'\n';return;} | ||
while(ipat>=0) | ||
{if(pat[ipat]!='}') | ||
{c=pat[ipat]; | ||
for(l=0;l<found.size();l++){if(found[l][pointr[l]]==c){pointr[l]--;if(pointl[l]>pointr[l])break;}} | ||
if(l<found.size())return;pastr=c+pastr;ipat--; | ||
} | ||
else | ||
{for(ipatp=ipat-1;pat[ipatp]!='{';ipatp--) | ||
{c=pat[ipatp];for(l=0;l<found.size();l++)if((found[l][pointr[l]])==c)break; | ||
if(l<found.size())forw=c+forw; else loop=c+loop;} | ||
if(!loop.empty()){pastr='{'+loop+'}'+pastr;} | ||
printresl(pointl,pastl,pat.substr(0,ipatp),pointr,pastr); | ||
for(i=0;i<forw.size();i++){ | ||
printresl(pointl,pastl,pat.substr(0,ipat+1)+forw[i],pointr,pastr);} | ||
return; | ||
} | ||
}checkpat(pastl+pastr); | ||
} | ||
|
||
ifstream kern; | ||
|
||
main(int argc, char *argv[]) | ||
{string p,pat,pp,ms,pref,prefms; | ||
int ip,ipat,ipatp,l,i; | ||
|
||
ms=argv[1]; | ||
pref="kernel"; prefms=pref+ms;b=atoi(argv[1]); | ||
kern.open(prefms.c_str()); | ||
for(char c='0';c<='9';c++){w[c]=0+c-'0';tr[0+c-'0']=c;} | ||
for(char c='A';c<='Z';c++){w[c]=10+c-'A';tr[10+c-'A']=c;} | ||
for(char c='a';c<='z';c++){w[c]=36+c-'a';tr[36+c-'a']=c;} | ||
for(i=2;i<b*b;i++)if(ok(i))fact.push_back(i); | ||
if(argc>2)m=atoi(argv[2]); else m=100000; | ||
while(cin>>pat) | ||
{cerr<<pat<<" keeps "<<"\n"; | ||
found.clear();pointl.clear();pointr.clear(); | ||
while(kern>>p) | ||
{ip=1;ipat=0; | ||
while(ipat<pat.size()) | ||
{if(pat[ipat]!='{'){if(p[ip]==pat[ipat]){ip++;ipat++;if(p[ip]=='"')break;}else ipat++;} | ||
else{ipatp=ipat+1;while(pat[ipatp]!='}') {if(p[ip]==pat[ipatp]) {ip++;break;} else ipatp++;} | ||
if(pat[ipatp]=='}')ipat=ipatp+1; | ||
} | ||
} | ||
if(p[ip]=='"'){ pp="";l=0;while(p[l]!='='){pp=pp+p[l];l++;} found.push_back(pp); | ||
pointl.push_back(1); pointr.push_back(l-2); cerr<<pp<<"\n";} | ||
} | ||
printresl(pointl,"",pat,pointr,""); | ||
kern.clear();kern.seekg(0,ios::beg); | ||
} | ||
//kern.close(); | ||
} // fin main |
748
code/rfb.cc
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <cmath> | ||
#include <list> | ||
#include <string> | ||
#include <vector> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
using namespace std; | ||
|
||
bool ok(long int n) // is prime? | ||
{unsigned int kk; | ||
if (n<2) return false; | ||
for (kk=2;kk*kk<=n;kk++) | ||
{if(n % kk==0)return false;} | ||
return true; | ||
} | ||
|
||
int main() | ||
{ | ||
int i,j,k; | ||
vector <double> sizem ( | ||
{0,0, 2, 3, 3, 8, 7, 9, 15, 12, 26, 152, 17, 228, 240, 100, 483, 1278, 50, 3458, 651, 2598, 1242, 6016, 306, 17584, 5662, 17200, 5782, 57252, 220, 79182, 45205, 57676, 56457, 182378, 6295, 314986, 106838, 230317, 37772, 689061, 4551, 900795, 255911, 323436, 399012, 1436289, 29103, 4365265, 189914}); | ||
j=0; | ||
for (i=2;i<sizem.size();i++)if(ok(i)){j++;cout<<"i="<<i<<" ==> "<<sizem[i]<<" :log/i: "<<log(sizem[i])/i<<" :log/log(i): "<<log(sizem[i])/log(i)<<" :log*log(i)/i: "<<log(sizem[i])*log(i)/i<<'\n';} | ||
cout<<'\n'; | ||
for (i=1;i<6;i++)cout<<"i="<<pow(2,i)<<" ==> "<<sizem[pow(2,i)]<<" :log/i: "<<log(sizem[pow(2,i)])/pow(2,i)<<'\n'; | ||
cout<<'\n'; | ||
for (i=1;i<4;i++)cout<<"i="<<pow(3,i)<<" ==> "<<sizem[pow(3,i)]<<" :log/i: "<<log(sizem[pow(3,i)])/pow(3,i)<<'\n'; | ||
cout<<'\n'; | ||
for (i=1;i<3;i++)cout<<"i="<<pow(5,i)<<" ==> "<<sizem[pow(5,i)]<<" :log/i: "<<log(sizem[pow(5,i)])/pow(5,i)<<'\n'; | ||
cout<<'\n'; | ||
for (i=1;i<3;i++)cout<<"i="<<pow(7,i)<<" ==> "<<sizem[pow(7,i)]<<" :log/i: "<<log(sizem[pow(7,i)])/pow(7,i)<<'\n'; | ||
cout<<'\n'; | ||
for (i=2;i<51;i++)cout<<"i="<<i<<" ==> "<<sizem[i]<<" :log/i: "<<log(sizem[i])/i<<'\n'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <stdlib.h> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <string> | ||
#include <stdio.h> | ||
using namespace std; | ||
|
||
main(int argc, char *argv[]) | ||
{string ms,pref,prefms,p,ss;int k=0,b;char s[5]; | ||
ifstream res;ofstream split; | ||
ms=argv[1];b=atoi(argv[1]); | ||
pref="x"; prefms=pref+ms; | ||
res.open(prefms.c_str()); | ||
while(res>>p){sprintf(s,"%d",k); | ||
ss="xx"+ms+'-'+s; | ||
split.open(ss.c_str(),ios::out); | ||
split<<p<<"\n";split.close(); | ||
k++;} | ||
} // fin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <stdlib.h> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <string> | ||
#include <stdio.h> | ||
using namespace std; | ||
|
||
main(int argc, char *argv[]) | ||
{string ms,pref,prefms,p,ss;int k=0,n,i;bool pasfin;char s[5]; | ||
ifstream res;ofstream split; | ||
ms=argv[1];n=atoi(argv[2]); | ||
pref="r"; prefms=pref+ms; | ||
res.open(ms.c_str()); | ||
while(true){sprintf(s,"%d",k);k++;i=0; | ||
ss=prefms+'-'+s; | ||
split.open(ss.c_str(),ios::out); | ||
while(i<n){pasfin=(res>>p);if(pasfin){split<<p<<"\n";i++;}else break;} | ||
if(pasfin) split.close();else break;} | ||
} // fin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <string> | ||
#include <iostream> | ||
#include <stdlib.h> | ||
|
||
using namespace std; | ||
|
||
main(int argc, char *argv[]) | ||
{string p; int i,j,jj,k,kk; | ||
while(cin>>p) | ||
{// cout<<p<<"\n"; | ||
for(i=0;i<p.length();i++) | ||
{if(p[i]=='{') | ||
{if(p[i-1]!='}'){for(j=i+1;p[j]!='}';j++) | ||
if(p[j]==p[i-1]){p.erase(i-1,1);i=i-2;j--;break;} | ||
if(p[j]!='}')continue; | ||
} | ||
else {for(k=i-2;p[k]!='{';k--) | ||
{for(j=i+1;p[j]!='}';j++)if(p[k]==p[j])break; | ||
if(p[j]=='}')break; | ||
} | ||
if(p[k]=='{'){while(p[k]!='}')p.erase(k,1);p.erase(k,1);i=k-1;continue;} | ||
} | ||
for(j=i+1;p[j]!='}';j++)jj=j+1; | ||
if(p[jj+1]!='{'){for(j=i+1;p[j]!='}';j++) | ||
if(p[j]==p[jj+1]){p.erase(jj+1,1);i--;break;} | ||
if(p[j]!='}')continue;i=jj; | ||
} | ||
else {for(k=jj+2;p[k]!='}';k++) | ||
{for(j=i+1;p[j]!='}';j++)if(p[k]==p[j])break; | ||
if(p[j]=='}')break; | ||
} | ||
if(p[k]=='}'){while(p[jj+1]!='}')p.erase(jj+1,1); | ||
p.erase(jj+1,1);i=i-1;continue; | ||
} | ||
|
||
} | ||
} | ||
} | ||
cout<<p<<"\n"; | ||
} | ||
} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <list> | ||
#include <string> | ||
#include <vector> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <stdlib.h> | ||
using namespace std; | ||
|
||
main(int argc, char *argv[]) | ||
{string ss,p,pp; | ||
ifstream all,part; | ||
all.open(argv[1]); | ||
part.open(argv[2]); | ||
// int i; | ||
// vector <string> oldv; | ||
// ms=argv[1]; pref="oldleft"; prefms=pref+ms; | ||
// old.open(prefms.c_str()); | ||
part>>p;all>>pp; | ||
while(true) | ||
{if(pp==p){if(!(all>>pp)){while(part>>p)cerr<<p<<'\n';break;}if(!(part>>p)){cout<<pp<<'\n';while(all>>pp)cout<<pp<<'\n';break;};continue;} | ||
cout<<pp<<'\n';if(!(all>>pp)){cerr<<p<<'\n';while(part>>p)cerr<<p<<'\n';break;} | ||
} | ||
} // fin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <string> | ||
#include <iostream> | ||
#include <stdlib.h> | ||
|
||
using namespace std; | ||
|
||
main(int argc, char *argv[]) | ||
{string oldl="";string newl; bool dup; | ||
while(cin>>newl) | ||
{if(oldl.length()!=newl.length()) dup=false; else | ||
{dup=true; | ||
for(int i=0;i<oldl.length();i++)if(oldl[i]!=newl[i]){dup=false;break;} | ||
} | ||
if(dup){cerr<<newl<<"\n";}else{cout<<newl<<"\n";oldl=newl;} | ||
} | ||
} // fin main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <list> | ||
#include <string> | ||
#include <vector> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <stdlib.h> | ||
using namespace std; | ||
|
||
main(int argc, char *argv[]) | ||
{string ms,pref,prefms,ss,p; bool test; | ||
ifstream old; | ||
int i; | ||
vector <string> oldv; | ||
ms=argv[1]; pref="oldleft"; prefms=pref+ms; | ||
old.open(prefms.c_str()); | ||
while(old>>p) | ||
{ss="";i=0; | ||
while(i<p.length()) | ||
{if(p[i]!='$'){ss.push_back(p[i]);i++;} | ||
else{ while(p[++i]!='$')true;i++; } | ||
}oldv.push_back(ss); | ||
} | ||
while(cin>>p) | ||
{test=false; | ||
for(i=0;i<oldv.size();i++)if(oldv[i]==p){test=true;break;} | ||
if(!test)cout<<p<<'\n'; else cerr<<p<<'\n'; | ||
} | ||
} // fin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <vector> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <stdlib.h> | ||
|
||
using namespace std; | ||
|
||
struct elem{vector <short int> t; | ||
}; | ||
struct node{list <short int> nexti; | ||
list <short int> l; | ||
vector <int> ptr; vector <short int> mp1; | ||
unsigned long int modmm1, modlmm1, gcd, gcdll, gcdf, gcdl, dist, nbl; | ||
bool court,final,loopnpb; | ||
}; | ||
// gcd= gcd des chiffres de tous les arcs menant au noeud | ||
// gcdll= gcd des chiffre des self-loops sur le noeud | ||
// gcdf= dernier sigma menant au noeud | ||
// gcdl= gcd des self-loops et sigmas précédents | ||
// modlmm1= gcd des chiffre des self-loops menant au noeud | ||
// modmm1= somme (modulo m-1) des arcs progressant vers le noeud | ||
// court= pas de boucle avant ni de découpage du premier sigma | ||
// final= noeud peut correspondre à des strings à tester | ||
// loopnpb= la boucle locale n'est pas première avec la base | ||
// nbl= nombre de boucles sur le chemin | ||
//nt= nbre max de boucles sur un chemin | ||
string tr; ifstream kern,R; | ||
void printelem(elem el) | ||
{int iti; | ||
cout<<'"'; | ||
for (iti=0;iti<el.t.size();++iti)cout<<tr[el.t[iti]]; | ||
cout<<'"'<<"\n";cout.flush();} | ||
|
||
bool cover(elem el1,elem el2) | ||
{int iti1,iti2; | ||
if(el1.t.size()<el2.t.size()) | ||
{cout<<"problème d'ordre:";cout<<"problème d'ordre";cout.flush(); | ||
printelem(el1);printelem(el2); | ||
} | ||
if(el1.t.size()==el2.t.size())return(false); | ||
iti1=0;iti2=0; | ||
while(iti2<el2.t.size()) | ||
{if(el1.t[iti1]==el2.t[iti2]){iti1++;iti2++; | ||
if((iti1==el1.t.size())&&(iti2<el2.t.size())){return(false);}} | ||
else{iti1++;if(iti1==el1.t.size()){return(false);}}} | ||
cout<<"problème de dominance entre\n";cout<<"problème de dominance\n"; | ||
printelem(el1);printelem(el2);cout.flush(); | ||
return(true); | ||
} | ||
|
||
void printnode(node el) | ||
{list<short int>::iterator iti; | ||
int i; | ||
// if(el.nexti.empty() && el.l.empty())return; | ||
cout<<"{"; | ||
for (iti=el.nexti.begin();iti!=el.nexti.end();++iti) | ||
{cout<<*iti;} cout<<"}[";cout.flush(); | ||
for (iti=el.l.begin();iti!=el.l.end();++iti) | ||
{cout<<*iti<<",";cout.flush();} | ||
cout<<"]";cout<<el.gcd<<","<<el.gcdl<<","<<el.gcdf<<","<<el.gcdll | ||
<<","<<el.modlmm1<<","<<el.modmm1<<";"<<el.court<<el.loopnpb<<el.final<<",["; | ||
for(i=0;i<el.mp1.size();i++)cout<<el.mp1[i]<<",";cout<<"]\n"; | ||
cout.flush();} | ||
|
||
unsigned int pgcd(unsigned long int i, unsigned long int j) | ||
{unsigned long int ii,jj,kk; if(i==0)return j;if(j==0)return i; | ||
if(j>i){ii=j;jj=i;} else {ii=i;jj=j;} | ||
while(jj!=0){kk=ii%jj;ii=jj;jj=kk;} | ||
return ii;} | ||
unsigned int min(unsigned int i, unsigned int j) | ||
{if(i<=j)return i;else return j;} | ||
bool ok(long int n) // is prime? | ||
{unsigned int kk; | ||
if (n<2) return false; | ||
for (kk=2;kk*kk<=n;kk++) | ||
{if(n % kk==0)return false;} | ||
return true; | ||
} | ||
|
||
short int si,i,i1,j,ii; | ||
unsigned long int m,g,jj,jjj,n,nn,ip, | ||
nn1p,nn1,nn2,nn2p,nn3,nn42,nn42p,nn43,nn4,nn5,nn6,nn7,nn7p,nn8,nn8p,nn9,nt; | ||
bool test; string p; char c; | ||
long int cpustarttime; double cputime; | ||
elem el; | ||
vector<elem> found; | ||
int ite,ite1,ite2; | ||
list<short int>::iterator iti1,iti2; | ||
node auto1;vector<int>xtend; | ||
|
||
void printstring(node auto0,string s,int m) | ||
{list<short int>::iterator iti; | ||
xtend.clear();nn++; | ||
for (iti=auto0.nexti.begin();iti!=auto0.nexti.end();++iti) | ||
xtend.push_back(*iti); | ||
for (iti=auto0.l.begin();iti!=auto0.l.end();++iti) | ||
xtend.push_back(*iti); | ||
auto0.nexti.clear();auto0.l.clear(); | ||
for (ii=0;ii<xtend.size();++ii) | ||
{i=xtend[ii]; // on allonge | ||
test=false; | ||
for (ite=0;ite<found.size();ite++) | ||
if(i==found[ite].t[auto0.ptr[ite]]){test=true; | ||
if(auto0.ptr[ite]==(found[ite].t.size()-1))break;} | ||
if(ite==found.size()) | ||
// il n'est pas couvert; test indique si c'est une self-loop | ||
{if(test){auto0.l.push_back(i);}else {auto0.nexti.push_back(i);}} | ||
} // fin de l'allongement | ||
test=true;j=0; for (iti=auto0.nexti.begin();iti!=auto0.nexti.end();++iti) | ||
{if(pgcd(m,*iti)==1)test=false;j=pgcd(j,*iti);} auto0.loopnpb=test; | ||
auto0.gcdll=j; // gcdll = gcd de la boucle locale | ||
if(auto0.nexti.size()>1)auto1.mp1.clear(); | ||
else if(auto0.nexti.size()==1) | ||
{jjj=auto0.mp1.size(); | ||
for(jj=0;jj<jjj;jj++) | ||
auto0.mp1.push_back((auto0.nexti.front()-auto0.mp1[jj]+m+1)%(m+1));} | ||
// | ||
iti=auto0.l.begin(); | ||
while(iti!=auto0.l.end()) | ||
if(pgcd(m,*iti)==1) iti++; else // *iti ne peut être un chiffre final | ||
{test=false;i=*iti; | ||
for (iti1=auto0.nexti.begin();iti1!=auto0.l.end();++iti1) | ||
{if(iti1==auto0.nexti.end())iti1=auto0.l.begin(); | ||
if(pgcd(m,*iti1)==1) // on teste si un chiffre final peut suivre | ||
{i1=*iti1;for (ite=0;ite<found.size();ite++) | ||
if(found[ite].t.size()==(2+auto0.ptr[ite])) | ||
if(i==found[ite].t[auto0.ptr[ite]]) | ||
if(i1==found[ite].t[auto0.ptr[ite]+1])break; | ||
if(ite==found.size()){test=true;break;} | ||
}} | ||
if(!test){cout<<"<<"<<*iti<<">>";iti=auto0.nexti.erase(iti);}else{iti++;} | ||
//suppression des chiffres non-terminaux qui ne peuvent être suivis d'un terminal | ||
} | ||
{cout<<"\n"<<nn<<":"<<s<<"["; | ||
for (iti=auto0.nexti.begin();iti!=auto0.nexti.end();++iti) | ||
cout<<tr[*iti]; | ||
cout<<"."; | ||
for (iti=auto0.l.begin();iti!=auto0.l.end();++iti) | ||
cout<<tr[*iti]; | ||
cout<<"]\n";printnode(auto0);} | ||
for(iti=auto0.nexti.begin();iti!=auto0.nexti.end();iti++) | ||
for(iti1=auto0.l.begin();iti1!=auto0.l.end();iti1++) | ||
{i=*iti;i1=*iti1; | ||
for(ii=0;ii<found.size();ii++) | ||
if(found[ii].t.size()==(2+auto0.ptr[ii])) | ||
if(i==found[ii].t[auto0.ptr[ii]]) | ||
if(i1==found[ii].t[auto0.ptr[ii]+1])break; | ||
if(ii<found.size())cout<<"<"<<*iti<<","<<*iti1<<"> ";} | ||
for(iti=auto0.l.begin();iti!=auto0.l.end();iti++) | ||
for(iti1=auto0.l.begin();iti1!=auto0.l.end();iti1++) | ||
{i=*iti;i1=*iti1; | ||
for(ii=0;ii<found.size();ii++) | ||
if(found[ii].t.size()==(2+auto0.ptr[ii])) | ||
if(i==found[ii].t[auto0.ptr[ii]]) | ||
if(i1==found[ii].t[auto0.ptr[ii]+1])break; | ||
if(ii<found.size())cout<<"<"<<*iti<<","<<*iti1<<"> ";}cout<<"\n";cout.flush(); | ||
ip++;if(p[ip]=='[')return;if(p[ip]=='{')ip=ip+3;c=p[ip];if(c>='A')i=10+c-'A';else i=c-'0'; | ||
{auto1=auto0;ite=0; | ||
for (ite=0;ite<found.size();ite++) | ||
{if((i)==found[ite].t[auto1.ptr[ite]])auto1.ptr[ite]++;} | ||
auto1.final=true;auto1.gcd=pgcd(pgcd(auto0.gcd,auto0.gcdll),i); | ||
auto1.modlmm1=pgcd(auto0.modlmm1,auto0.gcdll); | ||
auto1.modmm1=(auto0.modmm1+i)%(m-1); | ||
for(jj=0;jj<auto1.mp1.size();jj++) | ||
auto1.mp1[jj]=(i-auto1.mp1[jj]+m+1)%(m+1); | ||
if(!auto0.nexti.empty()) | ||
{auto1.gcdl=pgcd(pgcd(auto1.gcdl,auto1.gcdf),auto0.gcdll); | ||
auto1.gcdf=i;auto1.court=false;} | ||
else{jj=(auto1.gcdf)*m+(i); | ||
if(((jj-(i))/m)!=auto1.gcdf) | ||
{auto1.gcdl=pgcd(auto1.gcdl,auto1.gcdf); | ||
auto1.gcdf=(i);auto1.court=false;} | ||
else auto1.gcdf=jj;} | ||
printstring(auto1,s+c,m); | ||
} | ||
} | ||
|
||
void handlebase(unsigned int m) | ||
{string s;long int k,kkk;node auto0,auto1;short int i;int ii; | ||
found.clear(); | ||
for (i=0;i<min(m,10);i++)tr.push_back('0'+i); | ||
for (i=10;i<m;i++)tr.push_back('A'+i-10); | ||
while(kern>>p) | ||
{el.t.clear();//cout<<p<<"\n"; | ||
for(i=1;p[i]!='"';i++){if(p[i]<'A'){el.t.push_back(p[i]-'0');} | ||
else{el.t.push_back(10+p[i]-'A');}} | ||
found.push_back(el); | ||
} | ||
R>>p;ip=0;cout<<p<<"\n"; | ||
for (ite1=0;ite1!=found.size();++ite1) | ||
for (ite2=0;ite2!=ite1;++ite2)cover(found[ite1],found[ite2]); | ||
nn=0; | ||
// initialisation | ||
c=p[ip];if(c>='A')i=10+c-'A'; else i=c-'0'; | ||
auto0.nexti.clear(); auto0.l.clear(); auto0.ptr.clear(); | ||
for(j=0;j<m;j++)if(!ok(j))auto0.l.push_back(j); | ||
for (ite2=0;ite2!=found.size();++ite2) | ||
{if(i==found[ite2].t[0])ii=1; else ii=0;auto0.ptr.push_back(ii);} | ||
auto0.modmm1=i%(m-1); auto0.modlmm1=0; auto0.nbl=0; | ||
auto0.mp1.clear(); auto0.mp1.push_back(i); | ||
auto0.final=false;auto0.loopnpb=false;auto0.court=true; | ||
auto0.gcd=i; auto0.gcdl=0;auto0.gcdll=0;auto0.gcdf=i;s=c; | ||
printstring(auto0,s,m); | ||
} // fin du traitement de la base | ||
|
||
main(int argc, char *argv[]) | ||
{string ms,pref,prefms;int m,k; | ||
k=1;//for(k=1;k<argc;k++) | ||
{ms=argv[k];m=atoi(argv[k]); | ||
pref="kernel"; prefms=pref+ms; | ||
kern.open(prefms.c_str()); | ||
pref="R"; prefms=pref+ms; | ||
R.open(prefms.c_str()); | ||
handlebase(m);} | ||
} // fin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,355 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <vector> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <stdlib.h> | ||
|
||
using namespace std; | ||
|
||
struct elem{vector <short int> t; | ||
}; | ||
struct node{list <short int> nexti; | ||
list <short int> l; | ||
vector <int> ptr; vector <short int> mp1; | ||
unsigned long int modmm1, modlmm1, gcd, gcdll, gcdf, gcdl, dist; | ||
bool court,final,loopnpb; | ||
}; | ||
// gcd= gcd des chiffres de tous les arcs menant au noeud | ||
// gcdll= gcd des chiffre des self-loops sur le noeud | ||
// gcdf= dernier sigma menant au noeud | ||
// gcdl= gcd des self-loops et sigmas précédents | ||
// modlmm1= gcd des chiffre des self-loops menant au noeud | ||
// modmm1= somme (modulo m-1) des arcs progressant vers le noeud | ||
// court= pas de boucle avant ni de découpage du premier sigma | ||
// final= noeud peut correspondre à des strings à tester | ||
// loopnpb= la boucle locale n'est pas première avec la base | ||
string tr,p;char c; ifstream kern,R;ofstream result,control; | ||
void printelem(elem el) | ||
{int iti; | ||
control<<'"'; | ||
for (iti=0;iti<el.t.size();++iti)control<<tr[el.t[iti]]; | ||
control<<'"'<<"\n";control.flush();} | ||
|
||
bool cover(elem el1,elem el2) | ||
{int iti1,iti2; | ||
if(el1.t.size()<el2.t.size()) | ||
{control<<"problème d'ordre:";cout<<"problème d'ordre";cout.flush(); | ||
printelem(el1);printelem(el2); | ||
} | ||
if(el1.t.size()==el2.t.size())return(false); | ||
iti1=0;iti2=0; | ||
while(iti2<el2.t.size()) | ||
{if(el1.t[iti1]==el2.t[iti2]){iti1++;iti2++; | ||
if((iti1==el1.t.size())&&(iti2<el2.t.size())){return(false);}} | ||
else{iti1++;if(iti1==el1.t.size()){return(false);}}} | ||
control<<"problème de dominance entre\n";cout<<"problème de dominance\n"; | ||
printelem(el1);printelem(el2);result.flush();cout.flush(); | ||
return(true); | ||
} | ||
|
||
void printnode(node el) | ||
{list<short int>::iterator iti; | ||
int i; | ||
// if(el.nexti.empty() && el.l.empty())return; | ||
cout<<"{"; | ||
for (iti=el.nexti.begin();iti!=el.nexti.end();++iti) | ||
{cout<<tr[*iti];} cout<<"}[";cout.flush(); | ||
for (iti=el.l.begin();iti!=el.l.end();++iti) | ||
{cout<<tr[*iti]<<",";cout.flush();} | ||
cout<<"]";cout<<el.gcd<<","<<el.gcdl<<","<<el.gcdf<<","<<el.gcdll | ||
<<","<<el.modlmm1<<","<<el.modmm1<<";"<<el.court<<el.loopnpb<<el.final<<",["; | ||
for(i=0;i<el.mp1.size();i++)cout<<el.mp1[i]<<",";cout<<"]"; | ||
cout.flush();} | ||
|
||
unsigned int pgcd(unsigned long int i, unsigned long int j) | ||
{unsigned long int ii,jj,kk; if(i==0)return j; | ||
if(j>i){ii=j;jj=i;} else {ii=i;jj=j;} | ||
while(jj!=0){kk=ii%jj;ii=jj;jj=kk;} | ||
return ii;} | ||
unsigned int min(unsigned int i, unsigned int j) | ||
{if(i<=j)return i;else return j;} | ||
bool ok(long int n) // is prime? | ||
{unsigned int kk; | ||
if (n<2) return false; | ||
for (kk=2;kk*kk<=n;kk++) | ||
{if(n % kk==0)return false;} | ||
return true; | ||
} | ||
|
||
short int si,i,i1,j,ii; | ||
unsigned long int m,g,jj,jjj,n,nn, ip, | ||
nn1p,nn1,nn2,nn2p,nn3,nn42,nn42p,nn43,nn4,nn5,nn6,nn7,nn7p,nn8,nn8p,nn9; | ||
bool test; | ||
long int cpustarttime; double cputime; | ||
elem el; | ||
vector<elem> found; | ||
int ite,ite1,ite2; | ||
list<short int>::iterator iti1,iti2; | ||
node auto1;vector<int>xtend; | ||
|
||
void printstring(node auto0,string s,int m) | ||
{list<short int>::iterator iti; | ||
if((auto0.court)&&ok(auto0.gcdf)) | ||
{nn8p++; | ||
cerr<<"un prime court: "<<s<<" = "<<auto1.gcdf<<",\n";cerr.flush(); | ||
result<<s<<"\n";result.flush();return;} | ||
xtend.clear();nn++; | ||
for (iti=auto0.nexti.begin();iti!=auto0.nexti.end();++iti) | ||
xtend.push_back(*iti); | ||
for (iti=auto0.l.begin();iti!=auto0.l.end();++iti) | ||
xtend.push_back(*iti); | ||
auto0.nexti.clear();auto0.l.clear(); | ||
for (ii=0;ii<xtend.size();++ii) | ||
{i=xtend[ii]; // on allonge | ||
test=false; | ||
for (ite=0;ite<found.size();ite++) | ||
if(i==found[ite].t[auto0.ptr[ite]]){test=true; | ||
if(auto0.ptr[ite]==(found[ite].t.size()-1))break;} | ||
if(ite==found.size()) | ||
// il n'est pas couvert; test indique si c'est une self-loop | ||
{if(test){auto0.l.push_back(i);}else {auto0.nexti.push_back(i);}} | ||
} // fin de l'allongement | ||
if((nn%1)==0) | ||
{cout<<nn<<":"<<s<<"["; | ||
for (iti=auto0.nexti.begin();iti!=auto0.nexti.end();++iti) | ||
cout<<tr[*iti]; | ||
cout<<"."; | ||
for (iti=auto0.l.begin();iti!=auto0.l.end();++iti) | ||
cout<<tr[*iti]; | ||
cout<<"]\n";} | ||
if((!auto0.l.empty())||(!auto0.l.empty())) | ||
{test=true; | ||
for (iti=auto0.nexti.begin();iti!=auto0.nexti.end();++iti) | ||
if(pgcd(m,*iti)==1)test=false; | ||
for (iti=auto0.l.begin();iti!=auto0.l.end();++iti) if(pgcd(m,*iti)==1)test=false; | ||
// test= tous les arcs ont un facteur avec la base | ||
if(test) // on peut supprimer les successeurs car ils ont tous un diviseur avec m | ||
{//control<<"\n(1)";printnode(auto0); | ||
auto0.nexti.clear(); auto0.l.clear(); | ||
auto0.gcdll=0;auto0.loopnpb=true;nn1++;} | ||
} | ||
iti=auto0.l.begin(); | ||
while(iti!=auto0.l.end()) | ||
if(pgcd(m,*iti)!=1) // *iti ne peut être un chiffre final | ||
{auto1=auto0; | ||
for (ite=0;ite<found.size();ite++) | ||
{if((*iti)==found[ite].t[auto1.ptr[ite]])auto1.ptr[ite]++;} | ||
test=false; | ||
for (iti1=auto1.nexti.begin();iti1!=auto1.nexti.end();++iti1) | ||
if(pgcd(m,*iti1)==1) // on teste si un chiffre final peut suivre | ||
{for (ite=0;ite<found.size();ite++) | ||
{if((*iti1)==found[ite].t[auto1.ptr[ite]]) | ||
if(auto1.ptr[ite]==(found[ite].t.size()-1))break;} | ||
if(ite==found.size())test=true; | ||
} | ||
if(!test)for (iti1=auto1.l.begin();iti1!=auto1.l.end();++iti1) | ||
if(pgcd(m,*iti1)==1) | ||
{for (ite=0;ite<found.size();ite++) | ||
{if((*iti1)==found[ite].t[auto1.ptr[ite]]) | ||
if(auto1.ptr[ite]==(found[ite].t.size()-1))break;} | ||
if(ite==found.size())test=true; | ||
} | ||
if(!test){nn1p++;iti=auto0.nexti.erase(iti);}else{iti++;} | ||
} //suppression des chiffres non-terminaux qui ne peuvent être suivis d'un terminal | ||
else{iti++;} | ||
test=true;j=0; | ||
for (iti=auto0.nexti.begin();iti!=auto0.nexti.end();++iti) | ||
{if(pgcd(m,*iti)==1)test=false;j=pgcd(j,*iti);} auto0.loopnpb=test; | ||
auto0.gcdll=j; // gcdll = gcd de la boucle locale | ||
j=0; for (iti=auto0.l.begin();iti!=auto0.l.end();++iti)j=pgcd(j,*iti); | ||
//j=gcd des arcs forward | ||
if((!auto0.l.empty())||(!auto0.l.empty())) | ||
{ | ||
if (pgcd(pgcd(auto0.gcd,auto0.gcdll),j)!=1) // tous les digits ont un diviseur | ||
{//control<<"\n(2)";printnode(auto0); | ||
auto0.nexti.clear();auto0.l.clear(); | ||
auto0.gcdll=0;auto0.loopnpb=true;nn2++;} | ||
else if (pgcd(pgcd(pgcd(auto0.gcdl,auto0.gcdll),j),auto0.gcdf)!=1) | ||
// sigma et loop ont un diviseur | ||
{//control<<"\n(2')";printnode(auto0); | ||
auto0.nexti.clear();auto0.l.clear(); | ||
auto0.gcdll=0;auto0.loopnpb=true;nn2p++;} | ||
else if | ||
(pgcd(m-1,pgcd(auto0.modlmm1,pgcd(auto0.modmm1,pgcd(auto0.gcdll,j))))!=1) | ||
{//control<<"\n(3)";printnode(auto0); | ||
auto0.nexti.clear();auto0.l.clear(); | ||
auto0.gcdll=0;auto0.loopnpb=true;nn3++;} | ||
// si un arc forward est incompatible avec un ou plusieurs autres et si, en le conservant et en supprimant les arcs incompatibles, on contrevient aux règles 2, 2' ou 3, on peut supprimer cet arc forward pour la suite! | ||
else{iti=auto0.l.begin(); | ||
while(iti!=auto0.l.end()) | ||
{i=*iti;j=i; | ||
for(iti1=auto0.l.begin();iti1!=auto0.l.end();iti1++)if(iti!=iti1) | ||
{i1=*iti1;test=false; | ||
for(ii=0;ii<found.size();ii++) | ||
if(found[ii].t.size()==(2+auto0.ptr[ii])) | ||
if(i==found[ii].t[auto0.ptr[ii]]) | ||
if(i1==found[ii].t[auto0.ptr[ii]+1])break; | ||
if(ii<found.size()){ | ||
for(ii=0;ii<found.size();ii++) | ||
if(found[ii].t.size()==(2+auto0.ptr[ii])) | ||
if(i1==found[ii].t[auto0.ptr[ii]]) | ||
if(i==found[ii].t[auto0.ptr[ii]+1])break; | ||
if(ii<found.size())test=true; | ||
} | ||
if(!test)j=pgcd(j,i1); | ||
} // j=pgcd des compatibles avec i | ||
if (pgcd(pgcd(auto0.gcd,auto0.gcdll),j)!=1) // tous les digits ont un diviseur | ||
{//control<<"\n(4+2)";printnode(auto0); | ||
iti=auto0.l.erase(iti);nn42++;} | ||
else if (pgcd(pgcd(pgcd(auto0.gcdl,auto0.gcdll),j),auto0.gcdf)!=1) | ||
// sigma et loop ont un diviseur | ||
{//control<<"\n(4+2')";printnode(auto0); | ||
iti=auto0.l.erase(iti);nn42p++;} | ||
else if | ||
(pgcd(m-1,pgcd(auto0.modlmm1,pgcd(auto0.modmm1,pgcd(auto0.gcdll,j))))!=1) | ||
{//control<<"\n(4+3)";printnode(auto0); | ||
iti=auto0.l.erase(iti);nn43++;} | ||
else iti++; | ||
} | ||
} | ||
} | ||
// | ||
if(auto0.nexti.size()>1)auto1.mp1.clear(); | ||
else if(auto0.nexti.size()==1) | ||
{jjj=auto0.mp1.size(); | ||
for(jj=0;jj<jjj;jj++) | ||
auto0.mp1.push_back((auto0.nexti.front()-auto0.mp1[jj]+m+1)%(m+1));} | ||
if((auto0.loopnpb)&&(pgcd(m,auto0.gcdf)>1)) | ||
{auto0.final=false;nn4++;} | ||
else if((auto0.nexti.empty())&&(auto0.court) | ||
&&(!ok(auto0.gcdf))) | ||
{auto0.final=false;nn8++;} | ||
else if(1!=pgcd(m-1,pgcd(auto0.modlmm1, | ||
pgcd(auto0.modmm1,auto0.gcdll)))) | ||
{auto0.final=false;nn5++;} | ||
else if(pgcd(auto0.gcd,auto0.gcdll)!=1) | ||
{auto0.final=false;nn7++;} | ||
else if(pgcd(pgcd(auto0.gcdf,auto0.gcdl),auto0.gcdll)!=1) | ||
{auto0.final=false;nn7p++;} | ||
else if(!auto0.mp1.empty()) | ||
{test=true; | ||
for(jj=0;jj<auto0.mp1.size();jj++) | ||
if(pgcd(m+1,auto0.mp1[jj])==1){test=false;break;} | ||
if(test){auto0.final=false;nn9++;} | ||
} | ||
if(auto0.final&&auto0.loopnpb){result<<s<<"\n";result.flush();} | ||
if(!auto0.nexti.empty()) | ||
{s=s+"{"; | ||
for(iti=auto0.nexti.begin();iti!=auto0.nexti.end();++iti) | ||
s=s+tr[*iti];s=s+"}"; | ||
} | ||
if(auto0.final&&(!auto0.loopnpb)){result<<s<<"\n";result.flush();} | ||
if(p[ip]!='[') | ||
{if(p[ip]=='{'){while(p[ip]!='}')ip++;ip++;}c=p[ip];ip++; | ||
auto1=auto0;ite=0;if(c>='A')i=10+c-'A';else i=c-'0'; | ||
for (ite=0;ite<found.size();ite++) | ||
{if((i)==found[ite].t[auto1.ptr[ite]])auto1.ptr[ite]++;} | ||
auto1.final=true;auto1.gcd=pgcd(pgcd(auto0.gcd,auto0.gcdll),i); | ||
auto1.modlmm1=pgcd(auto0.modlmm1,auto0.gcdll); | ||
auto1.modmm1=(auto0.modmm1+i)%(m-1); | ||
for(jj=0;jj<auto1.mp1.size();jj++) | ||
auto1.mp1[jj]=(i-auto1.mp1[jj]+m+1)%(m+1); | ||
if(!auto0.nexti.empty()) | ||
{auto1.gcdl=pgcd(pgcd(auto1.gcdl,auto1.gcdf),auto0.gcdll); | ||
auto1.gcdf=i;auto1.court=false;} | ||
else{jj=(auto1.gcdf)*m+(i); | ||
if(((jj-(i))/m)!=auto1.gcdf) | ||
{auto1.gcdl=pgcd(auto1.gcdl,auto1.gcdf); | ||
auto1.gcdf=(i);auto1.court=false;} | ||
else auto1.gcdf=jj;} | ||
if(auto1.court && ok(auto1.gcdf)) | ||
{cout<<"un prime court: "<<(s+tr[i])<<" = "<<auto1.gcdf<<"\n";cout.flush(); | ||
result<<"un prime court: "<<(s+tr[i])<<" = "<<auto1.gcdf<<"\n";result.flush();} | ||
printstring(auto1,s+tr[i],m); | ||
} | ||
else for (iti=auto0.l.begin();iti!=auto0.l.end();++iti) | ||
{auto1=auto0;ite=0; | ||
for (ite=0;ite<found.size();ite++) | ||
{if((*iti)==found[ite].t[auto1.ptr[ite]])auto1.ptr[ite]++;} | ||
auto1.final=true;auto1.gcd=pgcd(pgcd(auto0.gcd,auto0.gcdll),*iti); | ||
auto1.modlmm1=pgcd(auto0.modlmm1,auto0.gcdll); | ||
auto1.modmm1=(auto0.modmm1+*iti)%(m-1); | ||
for(jj=0;jj<auto1.mp1.size();jj++) | ||
auto1.mp1[jj]=(*iti-auto1.mp1[jj]+m+1)%(m+1); | ||
if(!auto0.nexti.empty()) | ||
{auto1.gcdl=pgcd(pgcd(auto1.gcdl,auto1.gcdf),auto0.gcdll); | ||
auto1.gcdf=*iti;auto1.court=false;} | ||
else{jj=(auto1.gcdf)*m+(*iti); | ||
if(((jj-(*iti))/m)!=auto1.gcdf) | ||
{auto1.gcdl=pgcd(auto1.gcdl,auto1.gcdf); | ||
auto1.gcdf=(*iti);auto1.court=false;} | ||
else auto1.gcdf=jj;} | ||
if(auto1.court && ok(auto1.gcdf)) | ||
{cout<<"un prime court: "<<(s+tr[*iti])<<" = "<<auto1.gcdf<<"\n";cout.flush(); | ||
result<<"un prime court: "<<(s+tr[*iti])<<" = "<<auto1.gcdf<<"\n";result.flush();} | ||
printstring(auto1,s+tr[*iti],m); | ||
} | ||
} | ||
|
||
void handlebase(unsigned int m) | ||
{string s;long int k,kkk;node auto0,auto1;short int i;int ii; | ||
cpustarttime=clock();cout<<"traitement de la base "<<m<<"\n"; | ||
nn1p=0;nn1=0;nn2=0;nn2p=0;nn3=0;nn4=0;nn5=0; | ||
nn6=0;nn7=0;nn7p=0;nn8=0;nn8p=0;nn9=0; | ||
found.clear(); | ||
for (i=0;i<min(m,10);i++)tr.push_back('0'+i); | ||
for (i=10;i<m;i++)tr.push_back('A'+i-10); | ||
while(kern>>p) | ||
{el.t.clear(); | ||
for(i=1;p[i]!='"';i++){if(p[i]<'A'){el.t.push_back(p[i]-'0');} | ||
else{el.t.push_back(10+p[i]-'A');}} | ||
found.push_back(el); | ||
} | ||
|
||
R>>p;ip=0;cout<<p<<"\n"; | ||
for (ite1=0;ite1!=found.size();++ite1) | ||
for (ite2=0;ite2!=ite1;++ite2)cover(found[ite1],found[ite2]); | ||
|
||
nn=0; | ||
// initialisation | ||
result<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; | ||
c=p[ip];ip++;if(c>='A')i=10+c-'A';else i=c-'0'; | ||
{auto0.nexti.clear(); auto0.l.clear(); auto0.ptr.clear(); | ||
for(j=0;j<m;j++)if(!ok(j))auto0.l.push_back(j); | ||
for (ite2=0;ite2!=found.size();++ite2) | ||
{if(i==found[ite2].t[0])ii=1; else ii=0;auto0.ptr.push_back(ii);} | ||
auto0.modmm1=i%(m-1); auto0.modlmm1=0; | ||
auto0.mp1.clear(); auto0.mp1.push_back(i); | ||
auto0.final=false;auto0.loopnpb=false;auto0.court=true; | ||
auto0.gcd=i; auto0.gcdl=0;auto0.gcdll=0;auto0.gcdf=i;s=tr[i]; | ||
//construction des familles à explorer à partir du premier chiffre | ||
printstring(auto0,s,m); | ||
} | ||
cputime = clock()-cpustarttime; cputime=cputime/1000000; | ||
result<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; | ||
result<<"\nA la fin, on a exploré " | ||
<<nn<<" familles de nombres, et on a pu appliquer " | ||
<<nn1<<" règles 1, "<<nn1p<<" règles 1', " | ||
<<nn2<<" règles 2, "<<nn2p<<" règles 2', " | ||
<<nn3<<" règles 3, " | ||
<<nn42<<" règles 42, "<<nn42p<<" règles 42', "<<nn43<<" règles 43, " | ||
<<nn4<<" règles 4, " | ||
<<nn5<<" règles 5, "<<nn6<<" règles 6, "<<nn7<<" règles 7, " | ||
<<nn7p<<" règles 7', "<<nn8<<" règles 8, "<<nn8p<<" règles 8' et " | ||
<<nn9<<" règles 9, en " | ||
<<cputime<<" secondes\n"; result.flush(); | ||
} // fin du traitement de la base | ||
|
||
main(int argc, char *argv[]) | ||
{string ms,pref,prefms;int m,k; | ||
k=1;//for(k=1;k<argc;k++) | ||
{ms=argv[k];m=atoi(argv[k]); | ||
pref="control"; prefms=pref+ms; | ||
control.open(prefms.c_str(),ios::out); | ||
pref="res"; prefms=pref+ms; | ||
result.open(prefms.c_str(),ios::out); | ||
pref="kernel"; prefms=pref+ms; | ||
kern.open(prefms.c_str()); | ||
pref="R"; prefms=pref+ms; | ||
R.open(prefms.c_str()); | ||
handlebase(m); | ||
control.close();result.close();kern.close();} | ||
} // fin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
#include <list> | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <sstream> | ||
using namespace std; | ||
|
||
ifstream result;int deploy;string p; | ||
|
||
string itos(int i) // convert int to string | ||
{stringstream s;s << i;return s.str();} | ||
|
||
string cvrt(char c) | ||
{if((c>='0')&&(c<='9')) return itos(c-'0'); else return itos(10+c-'A');} | ||
|
||
void printstringM(string sM,string s,string sr) | ||
{int i,ki;char c; | ||
for(i=0;i<sr.length();i++)if(sr[i]=='{')break; | ||
else{sM="("+sM+")*M+"+cvrt(sr[i]);s=s+sr[i];} | ||
if(i<sr.length())sr=sr.substr(i+1,sr.length()-i);else sr=""; | ||
if(sr.empty()){cout<<"x:="<<sM<<":\n"; | ||
cout<<"isprime(x),"<<'"'<<p<<"->"<<s<<"="<<'"'<<",x;\n"; | ||
cout.flush();return;} | ||
c=sr[0];for(i=1;i<sr.length();i++)if(sr[i]=='}')break; | ||
sr=sr.substr(i+1,sr.length()-i); | ||
for(ki=0;ki<=deploy;ki++) | ||
{printstringM(sM,s,sr); | ||
s=s+c; | ||
sM="("+sM+")*M+"+cvrt(c); | ||
} | ||
} | ||
|
||
main(int argc, char *argv[]) | ||
{string ms,pref,prefms;int m,k; | ||
deploy=atoi(argv[argc-1]); | ||
for(k=1;k<argc-1;k++) | ||
{ms=argv[k];m=atoi(argv[k]); | ||
pref="res"; prefms=pref+ms; | ||
result.open(prefms.c_str()); | ||
cout<<"M:="<<m<<":\n"; | ||
cout.flush(); | ||
while(result>>p)if(p[0]=='%')break; | ||
while(result>>p)if(p[0]=='%')break; else printstringM("0","",p); | ||
result.close();} | ||
} // fin main |
27f2742
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/xayahrainie4793/minimal-elements-of-the-prime-numbers
Minimal elements for the base b representations of the primes > b for the subsequence ordering, for 2 <= b <= 36