Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef pair<long long, long long> ii;
- template<typename T>T pw(T a, T n) {
- if (n == 1) return a;
- T t = pw(a, n/2);
- return n&1 ? t*t*a : t*t;
- }
- long long n;
- long long l, r, mid, temp;
- priority_queue<ii, vector<ii>, greater<ii>> ans;
- void query() {
- cin >> n;
- if(n == 1 || n == 2) {
- cout << n << ' ' << 1 << '\n';
- cout << '\n';
- return;
- }
- r = n;
- for(long long i = 1; r != 2; ++i) {
- for(l = 2; l <= r; ) {
- mid = (l + r)/2; temp = pw(mid, i);
- if(temp >= n || temp < 0) r = mid - 1;
- else l = mid + 1;
- }
- if(pw(++r, i) == n) {
- ans.emplace(r, i);
- if(i%2 == 0)
- ans.emplace(-r, i);
- }
- }
- while(ans.empty() == false)
- cout << ans.top().first << ' ' << ans.top().second << '\n',
- ans.pop();
- cout << '\n';
- }
- int main() {
- //freopen("DNPREVOIA.inp", "r", stdin);
- //freopen("DNPREVOIA.out", "w", stdout);
- ios_base::sync_with_stdio(false);
- cin.tie(NULL); cout.tie(NULL);
- int t; cin >> t;
- while(t--) {
- query();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment