Project Euler – Problem 1

May 28, 2012 at 3:23 pm | Posted in Programming | 2 Comments

Recently I came across Project Euler. I always had trouble with applying problem-solving thinking to problems. Somone on IRC somwhere told me that these are the toughest problem he had ever faced in programming. I think its a good idea to test my abilities by solving these problems. Here is the first and easy one (easiest one ?):

/* Add all the natural numbers below one thousand that are multiples of 3 or 5. 
 * version 0.1

#include <stdio.h>
#include <stdlib.h>

int main(void)
  int i;
  unsigned long s = 0;
  for (i = 3; i < 1000; i += 3)
    s += i;

  for (i = 5; i < 1000; i += 5)
      if(i % 3) s += i;

  printf("%lu\n", s);

  return EXIT_SUCCESS;

After you solve a problem and give correct answer, it shows in your registered account as solved and a link to the forum thread is also provided where you can see different kinds of solutions posted in different languages. It also shows how many people so far have solved the problem. Thats a good measure of your intelligence (if very few has solved it). Iam using C language for now to solve problems as C is the only language I know currently. I think you must go ahead and give Project Euler a try.


Copyright © 2012 Arnuld Uttre, Village – Patti, P.O – Manakpur, Tehsil – Nangal, Distt. – Ropar, Punjab (INDIA)

Verbatim copying and distribution of this entire article are permitted worldwide, without royalty, in any medium, provided this notice, and the copyright notice, are preserved.



RSS feed for comments on this post. TrackBack URI

  1. […] mentioned Project Euler in my previous post. Next problem was little bit hard to do and I rewrote my code 3 times before I got it […]

  2. Well, this is a very bad way of solving this problem. Firstly, it is of O(n^2) complexity [I know you hate Math, but I hope you do a little asymptotic analysis every now & then]. It takes a lot of time & it can be easily solved in O(1) complexity !

    What you would have done if the question had 1 Trillion instead of 1000 ? Your above program would take weeks to give a result 😉

    cheers !

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

Blog at
Entries and comments feeds.

%d bloggers like this: