Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <list>
- #include <map>
- #include <set>
- #include <deque>
- #include <stack>
- #include <bitset>
- #include <algorithm>
- #include <functional>
- #include <numeric>
- #include <utility>
- #include <sstream>
- #include <iostream>
- #include <iomanip>
- #include <cstdio>
- #include <cmath>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- class StrongPrimePower {
- public:
- vector <int> baseAndExponent(string);
- };
- typedef long long ll;
- typedef long double ld;
- const ld eps = 1e-14;
- ld logbase(ld a, ld base)
- {
- return log(a) / log(base);
- }
- bool prime(int a){
- for( int i = 2; i < sqrt(double(a))+1 && i<a; i++ )
- if( a%i==0 )
- return false;
- return true;
- }
- double round(double a){
- double fract = a - floor(a);
- if( fract<0.5 )
- return floor(a);
- else
- return ceil(a);
- }
- vector <int> StrongPrimePower::baseAndExponent(string n) {
- int len = n.length();
- ll N = 0;
- for( int i = 0; i < len; i++ ){
- N*=10;
- N+=n[i]-'0';
- }
- for( int i = 2; i < logbase( ld(N),2 )+1; i++ ){
- ld num = pow( ld(N), 1/ld(i) );
- if( abs( round(num)-num ) <= eps && prime( int( round(num) ) ) ){
- vector<int> ret;
- ret.push_back( int(round(num)) );
- ret.push_back( i );
- return ret;
- }
- }
- return vector<int>();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement