WA verdict in MYSARA


can anyone help where did i go wrong
Thanking you

#include
#include <bits/stdc++.h>
using namespace std;

int search(long long int p,long long int q)
{
long long int count=0,rem1,rem2,div1,div2;
while(p!=0 && q!=0)
{
div1=p/2;
rem1=p-(2*div1);
p=p/2;

    div2=q/2;
    rem2=q-(2*div2);
    q=q/2;

    if(rem1==1 && rem2==0)
    {
        return -1;
    }
    if(rem1==1 && rem2==1)
    {
        count++;
    }
}
return count;

}
int main()
{
long long int t,n,arr[100000],i,flag=1,ret,mc=0;
cin>>t;
while(t–)
{
mc=0;
flag=1;
cin>>n;
for(i=0;i<n;i++)
{
cin>>arr[i];
}
for(i=1;i<n;i++)
{
if(arr[i]<arr[i-1])
{
flag=0;
break;
}
else
{
ret=search(arr[i-1],arr[i]);
if(ret==-1)
{
flag=0;
break;
}
else
{
mc=mc+ret;
}
}
}
if(flag==0)
{
cout<<“0”<<"\n";
}
else
{
ret=((int)( pow(2,mc) + 0.5))%(1000000007);
cout<<ret<<"\n";
}
}
return 0;
}

#include iostream is there in the beginning (sorry for that )

solution link - https://www.codechef.com/viewsolution/30729021

Read about
“modular exponentiation”

1 Like

Thank you :slight_smile:

1 Like