https://www.codechef.com/problems/DIVSUBS

https://www.codechef.com/viewsolution/36088532
MY solution is giving wrong ans…but i am not able to find out the problem in the code.

@hrit04 range of elements is given to be upto 10^9, try with long long int

https://www.codechef.com/viewsolution/36093325
here I have used the long long int but still getting the wrong naswer.

@hrit04 why is this second loop upto n?
image

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Solution using pegion hole principle [Accepted]
https://www.codechef.com/viewsolution/44127910
#include
#include
#include
using namespace std;

int main() {
int t;
cin>>t;
while(t–)
{
long long int n;
cin>>n;
long long int prefix[n+1]={0};
long long int a[n];
prefix[0]=1;
long long int sum=0;
for (long long int i=0;i<n;i++)
{
cin>>a[i];
}

    prefix[0]=0;
    
    for (long long int i=1;i<=n;i++)
    {
    
        prefix[i]=a[i-1]+prefix[i-1];
    }
    //for(auto i:prefix)
    //cout<<i<<" ";
    //cout<<endl;
    for (long long int i=0;i<=n;i++)
    {
        
        prefix[i]=(n+(prefix[i]%n))%n;
    }
    
    map<long long int, long long int> final;
    for(auto i:prefix)
    {
        if (final.find(i)==final.end())
            final[i]=1;
        else
            final[i]++;
    }
    
    
    
    long long int ans=999999999;
    int start=0;
    int end=0;
    //for(auto i:prefix)
    //cout<<i<<" ";
    //cout<<endl;
    for(auto i:final)
    {
        if (i.second>1)
        {
            ans=i.first;
            for(auto e=0;e<n+1;e++)
            {
                if (prefix[e]==i.first)
                {
                    start=e;
                    break;
                }
            }
            //cout<<start<<" start"<<endl;
            for(auto e=n;e>=0;e--)
            {
                if (prefix[e]==i.first)
                {
                    end=e;
                    break;
                }
            }
            //cout<<end<<" end"<<endl;
            //cout<<i.first<<"   "<<i.second<<endl;
            break;
        }
    }
    
    if(ans==999999999)
    ans=0;
    cout<<end-start<<endl;
    for(int i=start;i<end;i++)
    cout<<i+1<<" ";
    cout<<endl;
}

}