Hey a friend introduced me to Project Euler and having fun solving there problems. I'm a really newbie and only been programming for 5 days now so please explain everything like you would to child. If you dont know what Project Euler is, its math problems solved mainly with programming (google it). Just done Problem 3:
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
Solved it but there are some changes I would like to make to improve it, that I require your help for.
First I would like to add in x % 2 into the condition for the second FOR command ie replace y <= x with y <= x % 2. I thought I could simply replace the term but that didnt work also have tried creating a new integer and writing that equal to x%2 after the first IF command but that didnt work either.
Secondly at the moment the only way to see the prime factors is that the output only shows the prime factors once and non prime factors several times. I would like the code to show only the prime factors or even better the highest prime factor. I think I can do that with an ELSE command if I can get the x % 2 to work but how would you do it.
Thirdly I am using code blocks 8.02 as recommended in the tutorials the output only seems to show a certain number of outputs after that it deletes the top number to place the last number. How can I remove this and show all outputs?
Finally this is my first time using tags I have read the sticky but apologies if I get this wrong.
Code:#include <iostream> using namespace std; int main() { long long int num=600851475143LL; for ( int x=1 ; x<num ; x++) if ( num%x==0 ) for ( int y = 2; y <= x ; y++) if ( x % y == 0 ) cout<< x <<endl; }