Posted By

mju4t on 02/06/11


Tagged

project Euler


Versions (?)

Project Euler Problem 3


 / Published in: C++
 

  1. /*Alexander DeTrano
  2. Project Euler - Problem 3
  3. 2/5/2011
  4.  
  5. The prime factors of 13195 are 5, 7, 13 and 29.
  6.  
  7. What is the largest prime factor of the number 600851475143 ?
  8. */
  9.  
  10. #include <iostream>
  11. #include <math.h>
  12.  
  13. using namespace std;
  14.  
  15. int main() {
  16. long z=600851475143;
  17. cout<<"z="<<z<<endl<<endl;
  18.  
  19. for(int i=2;i<=sqrt(z);i++){
  20. while(z%i==0 && z!= i){
  21. cout<<"Current z="<<z<<endl;
  22. cout<<z<<"%"<<i<<"="<<z/i<<endl;
  23. z=z/i;
  24. cout<<"New z="<<z<<endl<<endl;
  25. }
  26. }
  27. }

Report this snippet  

You need to login to post a comment.