dont know why i am gettion compilation error
prog.cpp: In function 'long long int modInverse(long long int, long long int)':
prog.cpp:46: error: 'extendedEuclid' was not declared in this scope
#include<stdio.h>
#include<utility>
#include<algorithm>
using namespace std;
#define MOD 1000000007
#define LL long long
LL factorial[2000005];
LL pow(LL a, LL b, LL mod) {
LL x = 1, y = a;
while(b > 0) {
if(b%2 == 1) {
x=(x*y);
if(x>mod) x%=mod;
}
y = (y*y);
if(y>mod) y%=mod;
b /= 2;
}
return x;
}
LL modInverse(LL a, LL m) {
return (extendedEuclid(a,m).second.first + m) % m;
}
pair<LL, pair<LL, LL> > extendedEuclid(LL a, LL b) {
if(a == 0) return make_pair(b, make_pair(0, 1));
pair<LL, pair<LL, LL> > p;
p = extendedEuclid(b % a, a);
return make_pair(p.first, make_pair(p.second.second - p.second.first*(b/a), p.second.first));
}
int main()
{
int t,a,b,n,i;
factorial[1]=1;
for (i=2;i<=2000001;i++)
factorial[i]=(factorial[i-1]*i)%(MOD-1);
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&a,&b,&n);
LL nCr=((factorial[2*n]%(MOD-1))*(modInverse(factorial[n],(MOD-1))))%(MOD-1);
nCr=((nCr%(MOD-1))*(modInverse(factorial[n],(MOD-1))))%(MOD-1);
LL nCr_pow_c=pow(nCr,b,MOD-1);
LL a_pow_nCr_pow_c=pow(a,nCr_pow_c,MOD);
printf("%lld\n",a_pow_nCr_pow_c);
}
return 0;
}
Maybe because extendedEuclid isn't defined yet ?
You have to add its prototype before calling it.
Add pair<LL, pair<LL, LL> > extendedEuclid(LL a, LL b);
on the top of your file and it'll work ;)
Put function declaration :- pair<LL, pair<LL, LL> > extendedEuclid(LL , LL );
before
LL modInverse(LL a, LL m) {
return (extendedEuclid(a,m).second.first + m) % m;
}
You are trying to use extendedEuclid
before it first appears. To fix it, you can move the modInverse
function after the pair<LL, pair<LL, LL> > extendedEuclid(LL a, LL b)
one. Alternatively, just add the declaration pair<LL, pair<LL, LL> > extendedEuclid(LL a, LL b);
among your declarations early in the file.
Also, I would recommend you follow a good C++ tutorial or book of some kind, including coding style. Your code suggests that you've acquired a number of bad habits that may come from disorganized learning.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.