Thread: project Euler

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2020
    Posts
    425
    Quote Originally Posted by john.c View Post
    But I guess code is secret now.
    Still brute force, and the code isn't secret, just not that well written or interesting. Here's the most interesting bit:

    Code:
    struct Factor {
       uint64_t factor;
       uint64_t power;
    };
    
    
    struct Factor_List {
       uint32_t used;
       struct Factor factors[64];  // Any more than 64 unique factors means the number is way more than 2^64
    
    };
    
    
    int main(int argc, char *argv[])
    {
       find_primes(1000000000);
       struct Factor_List fl1,fl2;
       int limit = 125;
       uint64_t a = 2;
       uint64_t b = 3;
       find_factors(a/2, &fl1);  // Remove the factor of 2 from 'a'
       while(a < 1000000000) {
          int factors;
          find_factors(b, &fl2);
          factors = count_factors(&fl1,&fl2);
          if(factors > limit) {
              printf("The %ldth triangular number %ld has %d factors\n", a, a*(a+1)/2, factors);
              while(limit < factors)
                 limit *= 2;
          }
          a+= 2;
    
    
          find_factors(a/2, &fl1);  // Remove the factor of 2 from 'a'
          factors = count_factors(&fl1,&fl2);
          if(factors > limit) {
              printf("The %ldth triangular number %ld has %d factors\n", b, b*(b+1)/2, factors);
              while(limit < factors)
                 limit *= 2;
          }
          b+= 2;
       }
    }
    Last edited by hamster_nz; 05-20-2023 at 06:17 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help!! Problem 3 of Project Euler
    By i++ in forum C Programming
    Replies: 8
    Last Post: 08-15-2013, 06:59 PM
  2. Project Euler 22
    By deadrabbit in forum C Programming
    Replies: 1
    Last Post: 06-23-2012, 11:22 PM
  3. Project Euler problem
    By nimitzhunter in forum C++ Programming
    Replies: 6
    Last Post: 04-15-2012, 09:00 PM
  4. Project Euler
    By CodeGuru25 in forum C Programming
    Replies: 2
    Last Post: 01-13-2010, 06:25 AM
  5. Project Euler Question
    By Head In Jar Man in forum C++ Programming
    Replies: 6
    Last Post: 04-26-2009, 02:59 PM

Tags for this Thread