Created
September 30, 2016 22:28
-
-
Save andr1972/e04ca7a23956fa51436a085a3b9b528b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <boost/multiprecision/cpp_int.hpp> | |
#include <chrono> | |
using namespace boost::multiprecision; | |
using namespace std; | |
class stoper | |
{ | |
public: | |
chrono::time_point<chrono::high_resolution_clock> a, b; | |
void start() { a = chrono::high_resolution_clock::now(); } | |
void stop() { b = chrono::high_resolution_clock::now(); } | |
double duration() | |
{ | |
chrono::duration<double> elapsed_seconds = b - a; | |
return elapsed_seconds.count(); | |
} | |
}; | |
void factor(const cpp_int n) | |
{ | |
cpp_int x = n; | |
while ((x % 2) == 0) { | |
x /= 2; | |
std::cout << 2 << " "; | |
} | |
cpp_int i, e; | |
i = 3; | |
e = sqrt(x); | |
while (i <= e) { | |
while ((x % i) == 0) { | |
x /= i; | |
e = sqrt(x); | |
std::cout << i << " "; | |
} | |
i+=2; | |
} | |
if (x > 1) | |
std::cout << x << " "; | |
} | |
int main() | |
{ | |
cpp_int a("5742507205757425072053");// 3*7*197*402529*3448409664461 | |
double best = INFINITY; | |
for (int i=0; i<10; i++) | |
{ | |
stoper st; | |
st.start(); | |
factor(a); | |
st.stop(); | |
best = min(best, st.duration()); | |
} | |
printf("%f\n", best); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment