简体   繁体   English

编译错误C ++

[英]Compilation Error C++

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 ? 也许是因为还没有定义extendedEuclid吗?

You have to add its prototype before calling it. 您必须在调用它之前添加其原型。

Add pair<LL, pair<LL, LL> > extendedEuclid(LL a, LL b); 添加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 ); 放置函数声明: 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. 您正在尝试使用extendedEuclid ,使其首次出现。 To fix it, you can move the modInverse function after the pair<LL, pair<LL, LL> > extendedEuclid(LL a, LL b) one. 要解决此问题,您可以在pair<LL, pair<LL, LL> > extendedEuclid(LL a, LL b)一个后移动modInverse函数。 Alternatively, just add the declaration pair<LL, pair<LL, LL> > extendedEuclid(LL a, LL b); 或者,只需添加声明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. 另外,我建议您遵循一本不错的C ++教程或某种书籍,包括编码风格。 Your code suggests that you've acquired a number of bad habits that may come from disorganized learning. 您的代码表明您已经养成一些不良习惯,这些不良习惯可能是由于学习混乱造成的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM