I cant get the logic for the question in the above link .

I have seen a few submissions but why is it that summation of the values of A = no of pairs of A and B satisfying the given relation??

Proma Roy

Please Log in to answer

Note: Your answer should not be too short. Please wait a few seconds for the editor to load

Please make sure the answer is not too short

1 Answer

conan_0 14:18, Oct 24
Anupam Singh

The condition required is a^2+b<=y.

where, a can be any positive integer(non-zero)

and b varies from 1-700 inclusive.

we will exploit the fact here that b is bounded and can vary a for a given value of b.

So a^2<=(y-b) or a<=sqrt(y-b)

maximum value of a satisfying the above relation will be the floor value of sqrt(y-b) and 

numbers 1,2,3,4------,floor_value(sqrt(y-b)) will satisfy the above relation for that value of b.

So we just add all values of floor_value(sqrt(y-b)) for each b from 1-700(inclusive).

Here is the code,

using namespace std;
int  main()
    long long t;
        long long y,count=0;//since y can vary till 10^10
        for(int b=1;b<=700;b++)
                if(y>b)//y should be greater than b else sqrt(y-b) will give wrong value
                long long int numbers_of_a=floor(sqrt((double)(y-b)));

Please make sure the answer is not too short
No Comments yet