Skip to content

Instantly share code, notes, and snippets.

@soravux
Last active December 19, 2015 11:58
Show Gist options
  • Save soravux/5951200 to your computer and use it in GitHub Desktop.
Save soravux/5951200 to your computer and use it in GitHub Desktop.
Solution to the Project Euler problem #1 - For the multigrad blog (entry 6)
/* To compile with: gcc euler1_s6.c -nostartfiles -s -O3 -o euler1_s6 */
/* How many 3, 5 and 15 are there in 999 (below 1000) */
#define QTY3 ( 999 / 3 )
#define QTY5 ( 999 / 5 )
#define QTY15 ( 999 / 15 )
/* Their sums */
#define SUM3 ( 3 * ( QTY3 * (QTY3 + 1) / 2 ) )
#define SUM5 ( 5 * ( QTY5 * (QTY5 + 1) / 2 ) )
#define SUM15 ( 15 * ( QTY15 * (QTY15 + 1) / 2 ) )
/* The answer */
#define RESULT ( SUM3 + SUM5 - SUM15 )
#include <stdio.h>
void _start(void) {
printf("%u\n", RESULT);
asm("movl $1,%eax;"
"xorl %ebx,%ebx;"
"int $0x80"
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment