asgarlikanan

https://www.e-olymp.com/az/problems/2761

Aug 7th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
4CS 0.55 KB | None | 0 0
  1. /*
  2.     Author: Kanan Asgarli
  3.     https://www.e-olymp.com/az/problems/2761
  4. */
  5. #include <iostream>
  6. #include <cmath>
  7. using namespace std;
  8. int n, res, y, x, d1, d2, tests;
  9. int main()
  10. {
  11.     cin>>tests;
  12.     while(tests--){
  13.         cin>>n;
  14.         res = 1000000001;
  15.         for(int i = 1; i <= sqrt(n); i++)
  16.             if( n % i == 0 ){
  17.                 d1 = i;
  18.                 d2 = n/i;
  19.                 if((d1 + d2)%2 == 0){
  20.                     y = (d1 + d2)/2;
  21.                     x = y - d1;
  22.                     if( x > 0 && res > x )
  23.                         res = x;
  24.                 }      
  25.             }
  26.         if( res == 1000000001 )
  27.             res = -1;
  28.         cout<<res<<endl;
  29.     }
  30.     return 0;
  31. }
Add Comment
Please, Sign In to add comment