Results 1 to 6 of 6

Thread: need 2 factors to get as close to 32767 as possible

  1. #1
    Member
    Join Date
    Sep 2007
    Location
    Denmark
    Posts
    856
    Thanks
    45
    Thanked 104 Times in 82 Posts

    need 2 factors to get as close to 32767 as possible

    i need 2 factors between 20 and 250 that gets as close to 32767 (but not above this value
    the biggest i can come up with is 181x181 = 32761

    how ever i really wish to get close to around a 2:3 or 3:4 ratio (approximate) on the factors

  2. #2
    Programmer Bulat Ziganshin's Avatar
    Join Date
    Mar 2007
    Location
    Uzbekistan
    Posts
    4,497
    Thanks
    733
    Thanked 659 Times in 354 Posts
    write a program?

  3. #3
    Member
    Join Date
    Jun 2008
    Location
    G
    Posts
    372
    Thanks
    26
    Thanked 22 Times in 15 Posts
    Code:
    int tmp_i = 0;
    int tmp_j = 0; 
    		
    int min_a = 20;
    int max_a = 250;
    int min_b = 20;
    int max_b = 250;
    		
    int sol = 32767;		
    		
    for(int i = min_a; i <= max_a; i++){
            for(int j = min_b; j <= max_b; j++){
                    if(i*j <= sol){
                            if(i*j > tmp_i*tmp_j){
    			        tmp_i = i;
    			        tmp_j = j;
    			        System.out.println(i+" * "+j+" = "+i*j);
                            }
    		}else{
                            break;
                    }
    	}
    }
    Last edited by thometal; 8th January 2014 at 08:31.

  4. #4
    Member Jean-Marie Barone's Avatar
    Join Date
    Oct 2012
    Location
    Versailles, France
    Posts
    60
    Thanks
    15
    Thanked 4 Times in 3 Posts
    32767=7*31*151=217*151

  5. #5
    Member
    Join Date
    Jun 2008
    Location
    G
    Posts
    372
    Thanks
    26
    Thanked 22 Times in 15 Posts

  6. #6
    Member
    Join Date
    Sep 2007
    Location
    Denmark
    Posts
    856
    Thanks
    45
    Thanked 104 Times in 82 Posts
    Quote Originally Posted by Jean-Marie Barone View Post
    32767=7*31*151=217*151
    Doh i didn't think of looking at the prime factors, but thank you. this is perfect.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •