MATBREAK - Editorial

Please help!! what am I doing wrong ? The power function is working fine but still getting wrong answer See this

Thanks bro. It worked. Maybe I was missing some mod operation in my main code. I will check it out.

Can anyone help me in finding the error in my code?
https://www.codechef.com/viewsolution/32133299

hello geeks,
Please have a look on my code, I am getting segmentation fault.

#include
#include <bits/stdc++.h>
#include
#include
using namespace std;
#define ll long long int
#define mod 1e9+7

ll fxp(ll a,ll b,ll m)
{
if(b==2)
return (aa)%m;
if(b%2==0)
return fmod(fxp(a
a,b/2,m),mod);
return fmod(fxp(a,b-1,m)*a,mod);
}

void swap(ll &a,ll &b){ ll t=a; a=b; b=t;}

int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
ll n,A,s,res=0;
cin>>n>>A;
for(ll i=1;i<=n;i++)
{
s=fxp(A,2i-1,mod);
A=A
s;
res+=s;
res=fmod(res,mod);
}
cout<<res<<endl;
}
return 0;
}

Hi! I have been stuck with this problem for quite some time now but couldn’t seem to figure out where the problem is. I tried a lot of test cases but failed to find where does it fail. Can someone please help me figure out the problem? This is my code:

#include <iostream>
using namespace std;

long long inf = 1000000007;

long long calPow(long long a, long long n){
    long long temp;
    if(n == 1){
        return a;
    }
    
    long long t = calPow(a, n/2);
    if(n & 1){
        temp = t * t;
        temp %= inf;
        temp = temp * a;
        temp %= inf;
        return temp;
    }
    
    temp = t * t;
    temp %= inf;
    return temp;
}

int main(void) {
	// your code goes here
	int t;
	cin >> t;
	while(t--){
	    long long n, a;
	    cin >> n;
	    cin >> a;
	    long long p, sum = 0;
	    for(long long i = 1; i <= n; i++){
	        long long x = 2*i - 1;
	        p = calPow(a, x);
	        sum = (sum + p)%inf;
	        long long temp;
	        temp = a * p;
	        temp %= inf;
	        a = temp;
	    }
	    
	    cout << sum;
	}
	
	return 0;
}

can anyone help me solve this problem in python 3 , i solved it in c++ but not able to make the power function in python

#include
#include <math.h>
using namespace std;

int main() {
long long int i,j,n,t,x,p1,p2,sum;
cin>>t;
while(t–)
{
cin>>n>>x;
p1=x;
p2=1;
sum=0;
for(i=0;i<n;i++)
{
p1=(p1p2)%(1000000007);
p2=pow(p1,2
i+1);
sum=sum+p2%(1000000007);
}
cout<<sum%(1000000007)<<"\n";
}

return 0;

}

im getting WA for this code please help

#include
#include <math.h>
using namespace std;
long long int power(long long int a, long long int b){
if(b == 0)return 1;
if(b%2 == 0){
long long int c = power(a,b/2);
return (cc)%1000000007;
}
return (a
power(a,b-1))%1000000007;
}
int main() {
long long int i,j,n,t,x,p1,p2,sum,k;
cin>>t;
while(t–)
{
cin>>n>>x;
p1=x;
p2=1;
sum=0;
for(i=0;i<n;i++)
{A
p1=(p1*p2)%1000000007;
// cout<<p1<<"\n";

        //p2=pow(p1,2*i+1);
        p2=power(p1,2*i+1);
       // cout<<p2<<"\n";
        sum=sum+p2%1000000007;
       // cout<<p2<<"\n";
    }
    cout<<sum<<"\n";
}

return 0;

}
can you tell me why i still get WA

you should calculate power using your self power function and take modulo%1000000007 at every step, because for large value of a your power function will give garbage value as output.
refer this link->https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/

please someone can tell me whats the prob in my code i have done fastexpo as well
https://www.codechef.com/viewsolution/32208721

#include<iostream>
using namespace std;
long long int poww(long long int c,long long int d){
  long long int res=1;
  while(d--){
    res=((res%1000000007)*(c%1000000007))%1000000007;
  }
  return res%1000000007;
}
int main(){
  int t;
  cin>>t;
  while(t--){
    long long int n,a,s=0,p=1;

    cin>>n>>a;
    for(long long int i=1;i<=n;i++){
      p=poww(a,(2*i-1));
      s=((s%1000000007)+(p%1000000007))%1000000007;
      a=(((p)%1000000007)*((a)%1000000007))%1000000007;

    }
    cout<<s%1000000007<<endl;
  }
  return 0;
}

#this code gives me tle. please help.

whats wrong in this solution???

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

const ll int M = 1e9+7;
ll int n,A;

void solve(){
cin>>n>>A;
ll int sum = 0 ,prod = 1 , count = 1;

for(int i = n - 1 ; i>= 0 ; i--){
	prod = pow(A,count);
	sum += prod%M;
	count+=2;
	A = A*prod;
}



cout<<sum<<'\n';

}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);

int T;
cin>>T;
while(T–){
solve();
}

return 0;

}