Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Project Euler Problem 167
Posted:
Jul 11, 2009 9:36 AM


Hello Everyone I am trying to solve the project euler problem 167(http:// projecteuler.net/index.php?section=problems&id=167). I did some home work and wrote a c++ code to generate ulam numbers but it is not fast enough. I found something interesting on mathworld (http:// mathworld.wolfram.com/UlamSequence.html ) and online integer sequence (http://www.research.att.com/~njas/sequences/A007300) . According to online integer sequence U(2,5) ulam sequence can be generated as A(n) =A(n32)+126 leaving first six terms. I also found a paper of M.C. Wunderlich (http://www.springerlink.com/content/q782771118653276 ) but this paper is not accessible to my university. Can any one please send me to mukeshtiwariDOTiiitmATgmailDOTcom. My problem is how to generate all the terms efficiently and how to find a cycle.For Example U(2,5) lead to cycle 32 leaving first 6 terms so how to find about others.Is there any proof on the upper bound of cycles in sequecne U(2,2n+1).
Thanking you Mukesh Tiwaro
Here is my C++ code. #include<cstdio> #include<iostream> #include<map> using namespace std;
int main() {
int ulam_1[1003]; ulam_1[0]=2,ulam_1[1]=7,ulam_1[2]=9; int n=2; for(int cnt=0;cnt<1000;cnt++) { map<int,int>M; for(int i=0;i<n;i++) { for(int j=i+1;j<=n;j++) {
M[ulam_1[i]+ulam_1[j]]++; //cout<<ulam_1[i]<<"+"<<ulam_1[j]<<" "; } //cout<<endl; }
for(map<int,int>::iterator it=M.begin();it!=M.end();it++) { if(it>first<=ulam_1[n]) continue; if(it>second>=2) continue; //cout<<it>first<<">"<<it>second<<" "; ulam_1[++n]=it>first; break; }
//cout<<endl; cout<<"inserting ulam = "<<ulam_1[n]<<" "<<n<<endl; }
//for(int i=6;i+32<1000;i++) //if(ulam_1[i]+126==ulam_1[i+32]) cout<<"found with perriod 32 "<<ulam_1[i]<<" "<<ulam_1[i+32]<<endl; }



