Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define ll long long
- using namespace std;
- ll divisor_difference(ll n)
- {
- ll diff, ans = n - 1;
- int sqrtN = sqrt(n) + 1;
- for(ll i = 1; i <= sqrtN; i++)
- {
- if(n % i == 0)
- {
- ll j = n / i;
- diff = abs(i - j);
- if(diff < ans)
- ans = diff;
- }
- }
- return ans;
- }
- int main(void)
- {
- int t;
- ll n;
- cin >> t;
- for(int kase = 1; kase <= t; kase++)
- {
- cin >> n;
- printf("Case #%d: %lld\n", kase, divisor_difference(n));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement