FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Forum index » Science and Technology » Math » Recreational
Novel factorizations, episode IV
Post new topic   Reply to topic Page 1 of 1 [1 Post] View previous topic :: View next topic
Author Message
Risto Lankinen
science forum beginner


Joined: 02 Jun 2005
Posts: 28

PostPosted: Wed Jun 22, 2005 9:38 am    Post subject: Novel factorizations, episode IV Reply with quote

Hi!

Quote:
Begin Factors.cpp

#include <iostream.h>

// Rudimentary code! Number-to-factorize is hard-coded as 'N':
#define N 3*5*7*11*13 // 3*3*3*3*3*3*3*3*3*3 // 1001 // 1009


int Expand( int n )
{
int bit = 1;

while( n > 4*bit )
{
bit = bit * 2;
}

return bit * n;
}


int Oddify( int n )
{
while( (n&1) == 0 )
{
n = n/2;
}

return n;
}


void FindFactors( int x,int y,int b )
{
if( Expand(N)/y <= x || Expand(N)/(y+2*b) > (x+6*b) || b == 0 || x > 2*y )
{
if( Expand(N) == x*y )
{
cout << N << " = " << Oddify(x) << " * " << Oddify(y) << endl;

// Throw anything here to quit at first successful factorization
// Comment out or remove the line below to find all factorizations
throw "Done.";
}
return;
}

FindFactors( x,y,b/2 );
FindFactors( x+b,y,b/2 );
FindFactors( x+b/2,y+b/2,b/2 );
FindFactors( x+3*b/2,y+b/2,b/2 );
}


int main()
{
int n;

for( n=0x00008000;n!=0;n=n/2 )
{
if( n*n < Expand(N) )
{
try
{
FindFactors( n,n,n );
}
catch( ... )
{
break;
}
}
}

return 0;
}

Quote:
End Factors.cpp

Loosely based on the idea presented in...

http://groups.google.fi/groups?selm=2dCQd.37623%24g4.710392%40news2.nokia.com

Go ahead, try it out, analyze, get ideas, enjoy!

- Risto -
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [1 Post] View previous topic :: View next topic
The time now is Fri Nov 24, 2017 8:53 am | All times are GMT
Forum index » Science and Technology » Math » Recreational
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts *unique* prime factorizations; the fundamental theorem of... DGoncz@aol.com Math 5 Sun Jul 16, 2006 9:53 am
No new posts The grumble beast - sign of life? - Star Trek episode gb6724 New Theories 8 Sat Mar 04, 2006 2:16 pm
No new posts old NOVA episode "Race for the Top Quark" fred11 Particle 0 Tue Aug 16, 2005 7:42 pm
No new posts Factorizations of deterministic automata Jerry Swan Research 0 Tue Apr 05, 2005 10:42 am

Copyright © 2004-2005 DeniX Solutions SRL
Other DeniX Solutions sites: Electronics forum |  Medicine forum |  Unix/Linux blog |  Unix/Linux documentation |  Unix/Linux forums  |  send newsletters
 


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0462s ][ Queries: 15 (0.0226s) ][ GZIP on - Debug on ]