Comments
On shaanknightCodeCraft-20 (Div. 2), 6 years ago
0

See this loop from your submission:

for(ll i=0;i<n;i++){
    cin>>a[i];
    if(a[i]%p!=0)
        ans+=i;
}

You add the indices of every $$$a_i$$$ where $$$p$$$ doesn't divide $$$a_i$$$, instead of only adding the first index.

On shaanknightCodeCraft-20 (Div. 2), 6 years ago
+3

Transform each coefficient to $$$1$$$ if it is not divisible by p, and $$$0$$$ if it is. There will be $$$a_i$$$, $$$b_j$$$ such that $$$a_i = b_i = 1$$$. The answer is $$$i+j$$$.

I think that you need to send a new line when you print the answer.

cout << '!' << " " << ans;
cout.flush();

vs

cout << '!' << " " << ans << "\n";
cout.flush();