Project Euler is more about teaching a combination of number theory and programming than just about teaching programming :).
If you know nifty things about the numbers, you can approach a problem obliquely and come up with 'elegant' solutions.
For instance the amicable pair problem is fun to solve once you read up on the properties of Amicable Pairs
The other thing to consider is that you want to also take into account some programming shortcuts, like properties of numbers when represented in binary.
For example to check for an odd number compare:
int isOdd1(int x) { return (x % 2); }
vs.
int isOdd2(int x) { return x & 1; }
Here is the x86_64 disassembly of the two
0000000000000000 <isOdd1>:
0: 89 fa mov %edi,%edx
2: c1 ea 1f shr $0x1f,%edx
5: 8d 04 17 lea (%rdi,%rdx,1),%eax
8: 83 e0 01 and $0x1,%eax
b: 29 d0 sub %edx,%eax
d: c3 retq
e: 66 90 xchg %ax,%ax
0000000000000010 <isOdd2>:
10: 89 f8 mov %edi,%eax
12: 83 e0 01 and $0x1,%eax
15: c3 retq
Which one would you use ? :-)
So there are a lot of things to consider, and it's good to read up on other solutions to get hints, and to really think differently.
I hope this will get you more excited about programming :-)
Cheers,
Code for above:
isodd.c
int isOdd1(int x) {
return x % 2;
}
int isOdd2(int x) {
return x & 1;
}
To compile with gcc:
gcc -O99 -c -o isodd.o isodd.c
To see the disassembly with objdump:
objdump -d isodd.o
Output from objdump on an x86-64 platform
isodd.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <isOdd1>:
0: 89 fa mov %edi,%edx
2: c1 ea 1f shr $0x1f,%edx
5: 8d 04 17 lea (%rdi,%rdx,1),%eax
8: 83 e0 01 and $0x1,%eax
b: 29 d0 sub %edx,%eax
d: c3 retq
e: 66 90 xchg %ax,%ax
0000000000000010 <isOdd2>:
10: 89 f8 mov %edi,%eax
12: 83 e0 01 and $0x1,%eax
15: c3 retq