Find the middle divisor using square root of that number to 1
find divisor using square root:https://www.geeksforgeeks.org/find-divisors-natural-number-set-1/
///Bismillahir Rahmanir Rahim
///Author: Tanvir Ahmmad
///CSE,Islamic University,Bangladesh
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<iterator>
#include <functional> ///sort(arr,arr+n,greater<int>()) for decrement of array
/*every external angle sum=360 degree
angle find using polygon hand(n) ((n-2)*180)/n*/
///Floor[Log(b) N] + 1 = the number of digits when any number is represented in base b
using namespace std;
typedef long long ll;
int main()
{
ll tst,a;
cin>>tst;
while(tst--)
{
cin>>a;
ll sq=sqrt(a);
for(ll i=sq;i>=1;i--)
{
if(a%i==0)
{
cout<<abs((a/i)-i)<<endl;
break;
}
}
}
return 0;
}
///Alhamdulillah
problem link:https://www.codechef.com/LP2TO307/problems/RESQ
Comments
Post a Comment