Advertisement
Zeinab_Hamdy

Codechef62_7

Oct 28th, 2022
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.19 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define ull unsigned ll
  6. #define nl "\n"
  7. #define sz(x) x.size()
  8. #define NumOfDigit(w) log10(w) + 1
  9. #define fill(arr, val)  memset(arr, val , sizeof(arr))
  10. #define PI 3.141592654
  11. #define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
  12. #define all(v) v.begin(), v.end()
  13. #define rall(v) v.rbegin(), v.rend()
  14. #define fi first
  15. #define se second
  16. #define cin(v) for (auto&i:v) cin >> i;
  17. #define cout(v) for (auto&i:v) cout << i << " ";
  18. #define fixed(n) fixed << setprecision(n)
  19. #define MOD  1000000007
  20.  
  21.  
  22. void IO(){
  23.     ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  24. }
  25. void files(){
  26.     //freopen("filename.in" , "r" ,stdin);
  27.  
  28.             #ifndef ONLINE_JUDGE
  29.                      freopen("input.txt", "r", stdin);
  30.                      freopen("output.txt", "w", stdout);
  31.             #endif
  32. }
  33. /*
  34. #include <ext/pb_ds/assoc_container.hpp
  35. #include <ext/pb_ds/tree_policy.hpp>
  36. using namespace __gnu_pbds;
  37.  
  38. template <typename K, typename V, typename Comp = std::less<K>>
  39. using ordered_map = tree<K, V, Comp, rb_tree_tag, tree_order_statistics_node_update>;
  40. template <typename K, typename Comp = std::less<K>>
  41. using ordered_set = ordered_map<K, null_type, Comp>;
  42.  
  43. template <typename K, typename V, typename Comp = std::greater_equal<K>>
  44. using ordered_multimap = tree<K, V, Comp, rb_tree_tag, tree_order_statistics_node_update>;
  45. template <typename K, typename Comp = std::greater_equal<K>>
  46. using ordered_multiset = ordered_multimap<K, null_type, Comp>;
  47.  
  48. */
  49. bool prime(ll n){
  50.     if(n==2 || n==3) return true;
  51.     if(n<2 || n%2==0  ) return false;
  52.     for(int i=3;i<=sqrt(n);i+=2)   if(n%i==0) return false;
  53.     return true;
  54. }
  55.  
  56.  
  57. void solve(){
  58. ll n; cin >> n ;
  59.  
  60. for(ll i=1;i *i <= n ;i++){
  61.     ll x= n - (i*i);
  62.    ll sq=sqrt(x);
  63.     if( (sq*sq) + (i*i)==n){
  64.         return void (cout << sq << " " << i << nl);
  65.     }
  66. }
  67.  
  68. cout << -1 << nl;
  69.  
  70. }
  71. int main(){
  72.                  IO();          files();
  73.                  
  74.                  
  75.            
  76.     int testCase=1;  // one test case
  77.        cin >> testCase ;      
  78.  while(testCase--)
  79.         solve();  // my code
  80.        
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement