fork download
  1. #include <math.h>
  2. #include <iostream>
  3.  
  4. int FermatFactor(int oddNumber)
  5. {
  6. int a = sqrt(oddNumber)+1;
  7. int b2 = a*a - oddNumber;
  8. std::cout << "B2: " << b2 << "a: " << a << std::endl;
  9.  
  10. int tmp = sqrt(b2);
  11. while (tmp*tmp != b2)
  12. {
  13. a = a + 1;
  14. b2 = a*a - oddNumber;
  15. std::cout << "B2: " << b2 << "a: " << a << std::endl;
  16. tmp = sqrt(b2);
  17. }
  18.  
  19. return a + tmp;
  20. }
  21.  
  22. int main() {
  23. std::cout << "5959 => " << FermatFactor(5959) << std::endl;
  24. return 0;
  25. }
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
B2: 125a: 78
B2: 282a: 79
B2: 441a: 80
5959 => 101