Can anyone kindly help me out?

I dont understand why I’m getting WA…Please help me…
here is my code…
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
int t;
cin>>t;

while(t--){
   ll n, k;
   cin>>n>>k;

   if(k>=n)
    cout<<1<<endl;
   else
   {
       ll sq = sqrt(n);
       bool flag = 0;
       for(int i = sq; i >= 1; i--)
       {
           if(n%i == 0)
           {
               ll div = n/i;
               if(div <= k)
               {
                   cout<<i<<endl;
                   flag = 1;
                   break;
               }
               else if(i <= k)
               {
                   cout<<div<<endl;
                   flag = 1;
                   break;
               }
           }
       }
       if(!flag)
        cout<<n<<endl;
   }

}
return 0;

}

Problem is in else if part. Think will div be optimal?
You may see this

Code
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define lld long long int 

//-4%3=-1
int main() {
	// your code goes here
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t;
    cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        vector <int> v;
        for(int i=1;i<=sqrt(n);i++)
        {
            if(n%i==0)
            {
                if(i!=n/i)
                {
                    v.push_back(i);
                    v.push_back(n/i);
                }
                else
                v.push_back(i);
            }
        }
        sort(v.begin(),v.end());
        int i;
        //cout<<v.size()<<"A\n";
        for(i=v.size()-1;i>=0;i--)
        {
            //cout<<v[i]<<" ";
            if(v[i]<=k)
            break;
        }
        //cout<<v[i]<<"A";
        cout<<n/v[i]<<"\n";
    }
}

Can you give a test case where my code is not optimal?

You needed to find the maximum factor of n which is less than k so that number of packages would be minimised. Proceeding in this way will give WA as you are not checking other possible factors that might minimize the ans. store all the factors and then find the one which is less than k and is minimizes the number of packages (i.e max factor less than k.)

Yeah! I get it.Thanks