Skip navigation

This one was super easy. Took less then a second to execute. The trick is that you don’t have to check every number just every multiple of 20 and you don’t have to check each value from 1-20, just those that aren’t multipliers of others in the set. There’s also no point checking further if any of the numbers in the set aren’t multipliers.

#include <iostream>

int main (int argc, char * const argv[]) {
    unsigned int i;
    unsigned long long place = 20;
    bool notFound = true;
    bool skip;
    const int checks[9] = {
      19,18,17,16,15,14,13,12,11,
    };
    while(notFound){
      skip = false;
      place += 20;
      for(i=0;i<9;i++){
        if(place % checks[i]){
          skip = true;
          break;
        }
      }
      if(skip){
        continue;
      }
      std::printf("Found! %llu \n", place);
      notFound = false;
    }
    return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: