Advertisement
Guest User

Recursion depth hit

a guest
Feb 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <cmath>
  4.  
  5. static const long GOOBS = 600851475147;
  6.  
  7. template <long PF, long G, class Enable=void>
  8. struct Factor {
  9.     static const long result = G;
  10. };
  11.  
  12. // is factor
  13. template <long PF, long G>
  14. struct Factor<PF,G,std::enable_if_t<PF <= std::sqrt(G)>> {
  15.     static const long result = (G % PF) ?
  16.                         Factor<PF+2, G>::result : // is not factor
  17.                         Factor<PF, G/PF>::result; // is factor
  18. };
  19.  
  20. int main() {
  21.     std::cout << Factor<3, GOOBS>::result << "\n";
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement