diff --git a/archives/26/current b/archives/26/current new file mode 100755 index 0000000..add0132 Binary files /dev/null and b/archives/26/current differ diff --git a/archives/26/src/main.c b/archives/26/src/main.c new file mode 100644 index 0000000..7ac3ff2 --- /dev/null +++ b/archives/26/src/main.c @@ -0,0 +1,211 @@ +#include +#include "utils.h" +#include + +/* + A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given: + + 1/2 = 0.5 + 1/3 = 0.(3) + 1/4 = 0.25 + 1/5 = 0.2 + 1/6 = 0.1(6) + 1/7 = 0.(142857) + 1/8 = 0.125 + 1/9 = 0.(1) + 1/10 = 0.1 + Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring cycle. + + Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part. + + https://projecteuler.net/problem=26 +*/ + +boolean isPrime(int*primeList,int primeListSize,int numb) { + for (int i=0;i=1000) { + break; + } else { + primeList=realloc(primeList,sizeof(int)*++primeListSize); + primeList[primeListSize-1]=digit; + } + } + + while (divisor<1000) { + divider=10; //We always start with 10. + sequenceLength=0; + sequenceRepeat=0; + for (int i=0;i0&&found<20) { + for (int i=0;i +#include + +struct String mult(struct String numb1, struct String numb2) { + struct String n1 = numb1; + struct String n2 = numb2; + byte carryover = 0; + if (numb2.length>numb1.length) { + n1=numb2; + n2=numb1; + } + int addends[n2.length][n1.length+1]; + for (int i=0;i=0;i--) { + carryover=0; + for (int j=n1.length-1;j>=0;j--) { + int mult = (n1.str[j]-'0')*(n2.str[i]-'0')+((carryover!=0)?carryover:0); + //printf(" %d/%d\n",mult,carryover); + carryover=0; + if (mult>=10) { + carryover=mult/10; + mult=mult%10; + } + addends[(n2.length-1)-i][j+1]=mult; + } + if (carryover>0) { + addends[(n2.length-1)-i][0]=carryover; + } + } + //printIntDoubleArr(n2.length,n1.length+1,addends); + struct String sum = {1,"0"}; + for (int i=0;i=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]+((carryover>0)?carryover--:0); + } + //str[offset+1]='\0'; + } + } 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]+((carryover>0)?carryover--:0); + } + //str[offset+1]='\0'; + } + } + if (carryover>0) { + str = realloc(str,++digitCount); + str[digitCount-1]='1'; + //str[digitCount]='\0'; + } + for (int i=0;i