How to reduce time complexity for this??
#include<iostream>
using namespace std;
string choc(long long n)
{
long long m=n;
string p;
for(long long i=1;i<=n;i++)
{
if(m>=i)
{
m=m-i;
if(i%2!=0)
{
p='A';
}
else if(i%2==0)
{
p='B';
}
}
else
{
break;
}
}
return p;
}
int main()
{
long long t,n;
cin>>t;
while(t--)
{
cin>>n;
cout<<choc(n)<<endl;
}
}
Aucun commentaire:
Enregistrer un commentaire