Hi,
I started Project Euler sometimes ago and I have managed to finish problem 1 and 2 but now I am stuck on problem 3.As it says, I have implemented the code for 13195 but it doesn't work for 600851475143.
Code:#include <stdio.h> #include <stdlib.h> int main(void){ int i; int j=0; int k=2; int n=0; int number=13196; int factor[100]; int prime[100]; int isNotPrime; int largestPrime; for(i=1;i<number;i++){ if((number-1)%i==0){ //Factor is stored in the factor array factor[j]=i; for(k=2;k<(factor[j]);k++){ //if the remainder of jth factor and kth number is 0 if(factor[j]%k==0){ //isNotPrime stores jth factor isNotPrime=factor[j]; } } //If jth factor is not 1 and jth factor is not stored as isNotPrime if(factor[j]!=1 && isNotPrime!=factor[j]){ //prime stores jth factor at nth location prime[n]=factor[j]; //if nth prime is bigger than prime at first postion if(prime[n]>prime[0]){ //maxPrime stores nth prime largestPrime=prime[n]; }else{ //prime at first position is largest prime largestPrime=prime[0]; } n++; } j++; } } //Print results printf("The largest prime factor of 13195 is "); printf("%d\n",largestPrime); return EXIT_SUCCESS; }