Tên đăng nhập Điểm ▾ Bài tập Giới thiệu
2131 21929 334

include<bits/stdc++.h>>

define N 1123456

using namespace std;
long long i,j,k,n,t,x,m,a[N];
int bs(long long arr[],int n,long long x)
{
int d,c,g,ans=-1;
d=1;
c=n;
while(d<=c)
{
g=(d+c)/2;
if(a[g]==x)
return g;
if(a[g]>x)
{
ans=g;
c=g-1;
}
else
d=g+1;
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("a.inp","r",stdin);
//freopen("a.out","w",stdout);
cin>>n;
for(i=1; i<=n; i++)
a[i]=i*i+1;
cin>>t;
for(i=1; i<=t; i++)
{
cin>>x;
m=bs(a,n,x);
cout<<a[m]<<'\n';
}
}
//cach2:
//for(i=1;i<=t;i++)
//{
// cin>>x;
// m=lower_bound(a+1,a+1+n,x)-a;
// cout<<a[m]<<'\n';
//}
//}
//// cach 3:
//for(i=1;i<=t;i++)
//{
// cin>>x;
// m=upper_bound(a+1,a+1+n,x)-a;
// if(a[m-1]==x)
// m--;
// cout<<a[m]<<'\n';
//}
//}

2132 21927 44
2133
Itou_Arashi
Thường Xuân Âm 2k12
21924 250
2134 21921 12
2135
PY1ATruongPhuocQuyen 1344
Trương Phước Quyền
21921 258

thằng nào vô trang cá nhân thì thằng đó ...
english or spanish
you move you gay 🤫🤫🤫🤫🤫🧏‍♂️🧏‍♂️🧏‍♂️🧏‍♂️🧏‍♂️🧏‍♂️🧏‍♂️

2136
TanAZ 1617
21921 186

I'm gay

2137 21914 287

2138
PY2KPhamDuyKhoa 950
Phạm Duy Khoa
21907 256

“If you can't fly run, if you can't run then walk, if you can't walk then crawl, but whatever you do you have to keep moving forward.”

2139 21904 25
2140
SBD19_Duong
Hoàng Dương
21903 187

\(17th5\)