Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <math.h>
- #include <utility>
- #include <algorithm>
- using namespace std;
- class Root
- {
- private:
- std::vector<pair<unsigned int, unsigned int>> base;
- unsigned int root;
- unsigned int multipliquer;
- unsigned int root_degree;
- void simplyfy();
- public:
- Root(unsigned int root, unsigned int root_degree = 2)
- : root(root), root_degree(root_degree)
- {
- unsigned int max = pow(4294967294, 1.0/static_cast<double>(root_degree));
- for(unsigned int i = 2; i < max; i++)
- base.push_back(make_pair(i, pow(i, root_degree)));
- std::reverse(base.begin(), base.end());
- multipliquer = 0;
- this -> simplyfy();
- }
- void result();
- };
- void Root::simplyfy()
- {
- for(int i = 0; i < 3; i++)
- {
- for(auto x: base)
- if( root == x.second )
- {
- root = 1;
- multipliquer += x.first;
- return;
- }
- for(auto x: base)
- if( root > 1 && root % x.second == 0 )
- {
- root /= x.second;
- multipliquer += x.first;
- }
- }
- }
- void Root::result()
- {
- if ( multipliquer == 0 )
- cout << root_degree << "th degree root of " << root << "\n";
- else if ( root == 1 )
- cout << multipliquer << "\n";
- else
- cout << multipliquer << " * root(" << root << ") (" << root_degree << "th degree)\n";
- }
- int main()
- {
- unsigned int root, root_degree;
- while(cin >> root >> root_degree)
- {
- Root* x = new Root(root, root_degree);
- x -> result();
- cout << "\n\n>";
- delete x;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement