diff --git a/archives/21/current b/archives/21/current new file mode 100755 index 0000000..c9ba7d8 Binary files /dev/null and b/archives/21/current differ diff --git a/archives/21/src/main.c b/archives/21/src/main.c new file mode 100644 index 0000000..68efa7a --- /dev/null +++ b/archives/21/src/main.c @@ -0,0 +1,50 @@ +#include +#include "utils.h" + +/* + Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). + If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b are called amicable numbers. + + For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220. + + Evaluate the sum of all the amicable numbers under 10000. + + https://projecteuler.net/problem=21 +*/ + +int main(int argc,char**argv) { + int counter=1; + long totalSum=0; + while (counter<10000) { + //printf("Factor sum of %d: 1,",counter); + int factorSum=1; + int max=counter/2; + for (int i=2;i +#include + +struct String add(struct String numb1, struct String numb2){ + byte carryover=0; + int digitCount=0; + char*str = malloc(0); + if (numb1.length>=numb2.length) { + for (int offset=0;offsetoffset) { + //printf("%c %c\n",numb1.str[numb1.length-offset-1],numb2.str[numb2.length-offset-1]); + int sum=((numb1.str[numb1.length-offset-1]-'0')+(numb2.str[numb2.length-offset-1]-'0'))+((carryover>0)?carryover--:0); + if (sum>=10) { + carryover=1; + sum-=10; + } + str[offset]=sum+'0'; + } else { + str[offset]=numb1.str[numb1.length-offset-1]; + } + } + } else { + for (int offset=0;offsetoffset) { + //printf("%c %c\n",numb1.str[numb1.length-offset-1],numb2.str[numb2.length-offset-1]); + int sum=((numb1.str[numb1.length-offset-1]-'0')+(numb2.str[numb2.length-offset-1]-'0'))+((carryover>0)?carryover--:0); + if (sum>=10) { + carryover=1; + sum-=10; + } + str[offset]=sum+'0'; + } else { + str[offset]=numb2.str[numb2.length-offset-1]; + } + } + } + if (carryover>0) { + str = realloc(str,++digitCount); + str[digitCount-1]='1'; + } + for (int i=0;i=1901) { - //Start counting Sundays. - if (weekday==SUNDAY&&day==1) { - sundayCount++; + int counter=1; + long totalSum=0; + while (counter<10000) { + //printf("Factor sum of %d: 1,",counter); + int factorSum=1; + int max=counter/2; + for (int i=2;i