Beautiful arrays ICPC16B-Can some one say what is wrong with my code..i get a correct answer in other compilers..but code chef gives wrong answer..PLS HELP!

using namespace std;
int main()
int i,g,n,noe;
int* arr=NULL;
int* k=NULL;
cin >> n;
int flag=0;
int car=noe-1;
arr = new int[noe];
k= new int[car];
flag= ++flag;
if(flag == car)
return 0;


Your code gives a “Yes” for the following test case but it should not give a “Yes”.

Test Case:



2 0 3

in both the above cases the number is beautiful because the answer is one of the multiplicands right…Is that the case?An array a is called beautiful if for every pair of numbers ai, aj, (i ≠ j), there exists an ak such that ak = ai * aj. Note that k can be equal to i or j too.Here 1st pair ai =2,aj=0;2nd pair-ai=0,aj=3…Can you please tell what i understood is right or wrong?

Please include the test cases with the explanation…

Hey @sreeshu,

I think your approach is wrong.
For every value of Ak = Ai*Aj exist, then it’s for sure that a number greater than can be only one. If we have more than one number greater than one, so for that to happen we have to create a chain of never ending sequence.

assume 1,2,3

than to if 2 and 3 are present than 6 must also be present, if 6 is there than 12 and 18 should also be there and so on.

Now condition’s are only on 1 and -1. I want to you to figure it out yourself by making some test cases. If aren’t able to figure out than I’ll try to help you out.

You can also see this Code. for better explaination.

Hope this helps!

Thank you, Mr.Sandeep.I understood the concept after having working out your code…I understood your code better! but can you please do some corrections in my code which is posted above to get the result because I want to know that the array method which I have used is working or not!If possible pls can you do that?If you are busy don’t need

your welcome, @sreeshu

if you feel, your question is being answered than a gentle request to accept the answer so that this question can be removed from an unanswered question list.

Oh, i am sorry!