Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define ull unsigned ll
- #define nl "\n"
- #define sz(x) x.size()
- #define NumOfDigit(w) log10(w) + 1
- #define fill(arr, val) memset(arr, val , sizeof(arr))
- #define PI 3.141592654
- #define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define fi first
- #define se second
- #define cin(v) for (auto&i:v) cin >> i;
- #define cout(v) for (auto&i:v) cout << i << " ";
- #define fixed(n) fixed << setprecision(n)
- #define MOD 1000000007
- void IO(){
- ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
- }
- void files(){
- //freopen("filename.in" , "r" ,stdin);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
- /*
- #include <ext/pb_ds/assoc_container.hpp
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace __gnu_pbds;
- template <typename K, typename V, typename Comp = std::less<K>>
- using ordered_map = tree<K, V, Comp, rb_tree_tag, tree_order_statistics_node_update>;
- template <typename K, typename Comp = std::less<K>>
- using ordered_set = ordered_map<K, null_type, Comp>;
- template <typename K, typename V, typename Comp = std::greater_equal<K>>
- using ordered_multimap = tree<K, V, Comp, rb_tree_tag, tree_order_statistics_node_update>;
- template <typename K, typename Comp = std::greater_equal<K>>
- using ordered_multiset = ordered_multimap<K, null_type, Comp>;
- */
- bool prime(ll n){
- if(n==2 || n==3) return true;
- if(n<2 || n%2==0 ) return false;
- for(int i=3;i<=sqrt(n);i+=2) if(n%i==0) return false;
- return true;
- }
- ll BinEx(ll a , ll b ){
- ll res = 1;
- while (b){
- if (b& 1) res *=a ;
- a*= a;
- b /=2 ;
- }
- return res;
- }
- void solve(){
- ll n , x; cin >> n ;
- x=n;
- int cnt2=0;
- while(n%2==0){
- cnt2++; // get how many times n is divisble by 2
- n/=2 ;
- }
- // odd /
- if(cnt2&1) n*=2 , cnt2--; // to be perfect
- // 2^ ( even ) -> perfect square
- cnt2/=2 ; // as we * twice taht
- ll ans=BinEx(2,cnt2);
- for(ll i=0;i*i <=n; i++){ // n become smaller element after /2
- ll tmp = n - (i*i);
- ll sq=sqrt(tmp);
- // perfect square * perfect square = perfect square
- if(sq*sq + i*i == n )
- return void (cout << i * ans << " " <<
- sq * ans <<"\n" );
- }
- cout << -1 << nl;
- }
- int main(){
- IO(); files();
- int testCase=1; // one test case
- cin >> testCase ;
- while(testCase--)
- solve(); // my code
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement