10/11/2008

Project Euler : Solution au problème 5, en C

Dans l'enchaînement, une solution au problème 5, toujours en C. Attention, l'énoncé est particulièrement du type "on compte sur la vitesse d'exécution de l'ordinateur" et l'algorithme que j'ai vomi est particulièrement brutal et non-optimisé.

/* 2008/11/09 - euler5.c
 * Solution au Probleme 5 de Project Euler
 * http://projecteuler.net/index.php?section=problems&id=5
 * Jean Karim Bockstael - jkb@jkbockstael.be
 */
 
#include <stdio.h>

int euler5(int range) {
    int smallest=2520;
    int i;
    while (smallest++) {
        for (i=2; i<range+1; i++) {
            if ((smallest % i) != 0) {
                break;
                }
            }
        if (i==range+1) {
            return smallest;
            }
        }
    }

int main(int arc, char** argv) {
    printf("%i\n",euler5(20));
    return 0;
    }

Tags:

cc-by-nc | code (c) | project euler


Project Euler : Solution au problème 6, en C (11/11/2008)Project Euler : Solution au problème 4, en C (09/11/2008)