Problem with BINXOR? December long challenge

I got 10 points on the below solution for the BINXOR problem. Can’t figure out what it’s going wrong with.
Yes, I’m a noob, thanks for helping out.

using namespace std;
long long int f[100000]={0};
long long int fact(int n)
{
    if(f[n]==0)
        f[n]=(n*fact(n-1)) % 1000000007;
    //cout<<f[n]<<endl;
    return f[n];
}
int main()
{
    int t;
    f[0]=f[1]=1;
    cin>>t;
    while(t--)
    {
        int n,m0,m1,n0,n1,i,min,max;char a[100000],b[100000];
        long long int s=0;
        cin>>n;
        cin>>a;
        cin>>b;
        for(i=0,m0=m1=n0=n1=0;i<n;i++)
        {
            if(a[i]=='1')
                m1++;
            else if(a[i]=='0')
                    m0++;
            if(b[i]=='1')
                n1++;
            else if(b[i]=='0')
                    n0++;
        }
        
        if(m1>n1)
            min=m1-n1;
        else
            min=n1-m1;
        if(m1+n1>m0+n0)
            max=m0+n0;
        else
            max=m1+n1;
            
        for(i=min;i<=max;i+=2)
        {
            s+=(fact(n)/(fact(i)*fact(n-i)));
        }
        cout<<s%1000000007<<endl;
        

    }
}

Please either format your code or link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Sorry, just formatted it

1 Like

You are doing this : -
(to calculate nCr )

for(i=min;i<=max;i+=2) { s+=(fact(n)/(fact(i)*fact(n-i))); }

This is illegal and won’t work, google Lucas theorem and apply it to calculate nCr.(you are not applying modular arithmetic at all, check it.)

Will Lucas Theorem work here?
Here prime is 1e9+7.
Just asking :slightly_smiling_face:.

https://www.codechef.com/viewsolution/28063462
This will help

Fermat little theorem will work here.