Comments

Thanks for telling that. I will remember this thing in future

I got it. Thanks

Thanks

Thanks for the the integral proof

That's a great way to check the upper bound on number of times the loop will run. I will try this from next time.But can you comment a bit about the complexity? Is it like linear. Thanks

Do you wanna conclude that the complexity is almost linear?

Hey actually this question is part of a company's hiring process and I don't think that they will be expecting something like this. By the way your idea was nice. Thanks

By the way , can you think something like applying kadane's algorithm in diagonal elements because one of my friends said that it can be done in O(N2) and he tried to explain something like apply kadane algorithm in diagonal elements but I couldn't get what he wanted to say.

Actually I have to appear for the coding round for a company coming to my campus. They gave a pdf file containing a sample test and I just copied this from that. Since the constraint is N ≤ 1000 , I thought it had to be done in O(N2). But now I think may be they will do the code review or something like that to check the correctness of code.

Auto comment: topic has been updated by jha_gaurav98 (previous revision, new revision, compare).

Yes it worked. I declared the variable globally as follows:

vector < int > adj[100005];

and it worked fine.But why it didn't work inside the main?

-9

1) But then how it is working when n = 1000 .

2) According to you , instead of n + 1 we need to give some constant value for length so that compiler can understand it during compile time.So , I changed the above line of code as follows:

vector < int > adj[100005];

keeping in mind that value of n can never exceed 105. But then also the program crashes.

3) And then I did the same declaration globally(outside the main function) and it worked well.

I have tested the code using debug statements. The program crashes as soon as I create the adjacency list using following line of code:

vector < int > adj[n + 1];

I am first taking n (number of vertices) as input and then creating an array of vectors of size n + 1 for creating adjacency list.When I test the code for n = 1000 , it works fine but not for n = 100000. By the way I am using windows.

Thanks a lot friend. I just can't believe I missed that and wasted a lot of time.

Thanks bro

In problem E for every prime divisor i of n , we are calculating the number of ways of putting 'cnti' objects into 'y' boxes.

Or in other word the number of non-negative integral solution of equation x1+x2+x3+....+xY = cnti.

And this should be equal to (cnti+y-1)C(y-1) .

What is wrong in this logic? And if it is correct then how that formula came which you wrote over there?