
Algorithms Algorithms and Data Structures  Analysis, Graph, Search, String, Sorting, Merge, Compression, Optimization, Quantum 
 LinkBack  Thread Tools  Display Modes 
November 26th, 2010, 02:34 PM  #1 
Joined: Nov 2010 Posts: 1  List of numbers
How can I find/program a list of: We only operate with natural numbers. 1. The prime numbers < 10 000 2. x = a^2 + b^2 < 10 000 3. x = a^3 + b^3 < 10 000 4. x = a^2 + b^2 + c^2 < 10 000 5. x = a^3 + b^3 + c^3 < 10 000 Thank you. 
My Computer Forum is free to register and we welcome everyone! 
December 3rd, 2010, 11:48 PM  #2 
Site Founder Joined: Dec 2007 Posts: 414  Re: List of numbers
You could write such a program easily: 1. Use Eratosthene's sieve 2 and following: bound the values of a, b, c (obvious bounds) and test for all the possibilities within your boundaries 
February 16th, 2011, 09:09 AM  #3 
Joined: Feb 2011 Posts: 3  Re: List of numbers Code: void q2(int x){ int a,b; for(a=1;a<=71;a++) //2*71^2 <= 10'000 for(b=a;b<=71;b++) if (a*a+b*b==x) printf("%d %d\n",a,b); } 
May 17th, 2012, 10:54 AM  #4 
Joined: Feb 2011 Posts: 3  Re: List of numbers Code: #define N 10000 main() { int i, j, t[N]={0,0,1}; for( i=3; i<N; i++ ) t[i]=2; for( i=2; i<N; i++ ) for( j=i+1; j<N; j++ ) t[j] = (t[j]*i) % j; for( i=0; i<N; i++ ) if(t[i]) printf("%d ", i); } 
May 23rd, 2012, 09:09 AM  #5 
Site Founder Joined: Dec 2007 Posts: 414  Re: List of numbers
This algorithm was improved over the years 

Tags 
list, numbers 
Thread Tools  
Display Modes  

Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Question about linked list  fishsticks1907  Algorithms  1  February 16th, 2012 06:49 AM 
Add to the list if you can  asbo  New Users  0  May 1st, 2010 02:51 AM 