TWOVRIBL - Editorial

I think @samarthtandon helped.

1 Like

still not work…,.,.,.,.

OMG… I took 54.
Couldn’t regret more… :man_facepalming:

check it wisely…may me there is some other mistakes as well… I only see your scanf line and that was wrong…try to google about format specifiers in C language

I got TLE with the same logic of square root when i used int as a datatype but got AC when i used long long. Can someone please explain???

https://www.codechef.com/viewsolution/25401260
Can somebody check my code?

Can you store a value like “3105257559075038852” without quotes in int datatype?.
Obviously you cannot, here unsigned/signed long long int comes as a life saver
considering input: X_F = 1000000000(Which means 10^9)
The value of Y that you will get as output at the end will be “3105257559075038852”
Which means that our value of Y is somewhere around in the program execution is crossing the max value of int leading to wrong answer.
Hope it helps. :slight_smile:

1 Like

Your code for Input : X_F = 10^9
Output: 1
Expected Output: 59
Also, your code gives you wrong answer for some of the case like:
For X_F = 92 Your Output : 30
Expected : 32
Also with X_F = 101212 Your Output : 30
Expected : 32
Try to change your code.

:sweat_smile:
Thanks a lot, man. Will note the words of my elder brother.
:+1:

1 Like

please share the code

In case you had not already read this : My strategy at AtCoder & CS Academy - Codeforces

I told you about point 5 in the article… ; you may read the rest…!

Tricky question! :smile:

@suman_ptnl CodeChef: Practical coding for everyone my submission for that question.

Can somebody explain the binary search logic for this problem.

can you tell how it clicked you for choosing P as sqrt(Y) + 1 ?
Thanks in advance !!

1 Like

Hey thanks for asking!
Idea : I’ve considered PP = Y, then it took me to a
Step: P_obtained = sqrt(Y)
but given that P
P > Y, so it gave me an idea of increasing obtained P value by 1 so that it satisfies original constraints.
Final P = sqrt(Y) + 1;
I’ll elaborate this in a more understandable way if you really want to.
:sweat_smile:

I get SIGSTOP. I used the same approach. Plz help!!!

#include
using namespace std;

int find(long y_sqr,long X,long Xf)
{
int left=X+1,right=10000,mid;
long num=0,distance_from_X=99990;
while(left<=right)
{
mid=(left+right)/2;
if(mid*mid<=y_sqr)
{
left=mid+1;
}
else
{
if(mid-X < distance_from_X)
{
num=mid;
distance_from_X=mid-X;
}
right=mid-1;

    }
}
return num;

}

int main()
{
long T;
cin>>T;
while(T–)
{
long Xf;
cin>>Xf;
long X=0,Y=0,P=0,steps=0;
while(PP < XfXf)
{
P=find(Y,X,Xf);
if(PP<=XfXf)
{
Y+=P*P;
X=P;
steps++;
}

    }
    if(P!=X)
    {steps++;}
    cout<<steps<<" ";
}
return 0;

}

It would be really great if you could.

1 Like

Question. Whatever the value of Y, we have to choose a P (Positive Integer) such that P^2 > Y, find P ?.
Solution: Given: P^2 > Y, find P.
Whatever the problem may be, we have to first look into a case that makes our problem easier to solve for us. Here, all the possible possibilities that are possible :

  1. P^2 < Y
  2. P^2 = Y (Easier as it looks like a problem to solve a when a^2 = some b)
  3. P^2 > Y

This all about basic math. Now, taking possibility no.2 P^2 = Y
P.P = Y
Now, P = Y ^(1/2)
Which means P = sqrt(Y)

Now, what was asked in the question? P.P > Y
So, P that satisfies P.P = Y is sqrt(Y), now the least value(positive Integer) P that satisfies P.P > Y is
P = sqrt(Y) + 1; [suppose P = 4, which means Y = P^2 is 16, Now P that satisfies P^2 > Y is (4 + 1) = 5]

What if it was asked in the question like this choose P such that P^2 < Y
Now, we know P = sqrt(Y) - 1;

3 Likes

Thanks a lot for great explaination