Last active
June 6, 2016 18:00
-
-
Save balamark/51b4df92b11b6f2abac312492429b2be 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
| using namespace std; | |
| using ll = long long; | |
| class StrongPrimePower { | |
| public: | |
| bool isPrime(int p){ | |
| for(int i=2;i*i<=p;++i) if(p%i==0) return false; | |
| return true; | |
| } | |
| vector<int> baseAndExponent(string sn) { | |
| ll n = stoll(sn); | |
| for(int q=2;q<=59;++q){ | |
| double dp = pow(n, 1.0/q);//double pow (double base, double exponent); | |
| // cout<<dp<<endl; | |
| int p = round(dp);//don't cast, that's round down | |
| if(!isPrime(p)) continue;//p needs to be prime | |
| ll x=1L; | |
| for(int i=0;i<q;++i) x*=p;//raise it to the q-th power, and check if it equals to n | |
| if(x==n) return {p,q}; | |
| } | |
| return {}; | |
| } | |
| }; | |
| // we can see n^2/1, n^3/1 ... as follows | |
| Expected: [ 2, 59 ] | |
| Testcase #4 ... | |
| 759250124.99 | |
| 832255.32 | |
| 27554.49 | |
| 3565.78 | |
| 912.28 | |
| 344.55 | |
| 166.00 | |
| 94.06 | |
| 59.71 | |
| 41.17 | |
| 30.20 | |
| 23.24 | |
| 18.56 | |
| 15.28 | |
| 12.88 | |
| 11.09 | |
| 9.70 | |
| 8.61 | |
| 7.73 | |
| 7.01 | |
| 6.42 | |
| 5.92 | |
| 5.50 | |
| 5.13 | |
| 4.82 | |
| 4.55 | |
| 4.31 | |
| 4.10 | |
| 3.91 | |
| 3.74 | |
| 3.59 | |
| 3.45 | |
| 3.33 | |
| 3.22 | |
| 3.11 | |
| 3.02 | |
| 2.93 | |
| 2.85 | |
| 2.78 | |
| 2.71 | |
| 2.65 | |
| 2.59 | |
| 2.53 | |
| 2.48 | |
| 2.43 | |
| 2.39 | |
| 2.34 | |
| 2.30 | |
| 2.27 | |
| 2.23 | |
| 2.20 | |
| 2.16 | |
| 2.13 | |
| 2.10 | |
| 2.08 | |
| 2.05 | |
| 2.02 | |
| 2.00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment