Compile Error
/in/foo.cc: In function 'double c(int, int)': /in/foo.cc:9:48: error: invalid operands of types 'double' and 'double' to binary 'operator%' for(int i=2;i<=m;i++)sa=(sa+log((double)i))%mod; ~~~~~~~~~~~~~~~~~~~^~~~ /in/foo.cc:10:48: error: invalid operands of types 'double' and 'double' to binary 'operator%' for(int i=2;i<=n;i++)sb=(sb+log((double)i))%mod; ~~~~~~~~~~~~~~~~~~~^~~~ /in/foo.cc:11:50: error: invalid operands of types 'double' and 'double' to binary 'operator%' for(int i=2;i<=n-m;i++)sc=(sc+log((double)i))%mod; ~~~~~~~~~~~~~~~~~~~^~~~ /in/foo.cc: In function 'int main()': /in/foo.cc:18:22: error: invalid operands of types 'double' and 'double' to binary 'operator%' cout<<exp(c(m,n))%mod; ~~~~~~~~~~~^~~~
代码
#include<iostream>
#include<cmath>
using namespace std;
double mod=1000000007;
double c(int m,int n)
{
double sa,sb,sc;
sa=sb=sc=0.0;
for(int i=2;i<=m;i++)sa=(sa+log((double)i))%mod;
for(int i=2;i<=n;i++)sb=(sb+log((double)i))%mod;
for(int i=2;i<=n-m;i++)sc=(sc+log((double)i))%mod;
return sb-sa-sc;
}
int main()
{
int m,n;
cin>>m>>n;
cout<<exp(c(m,n))%mod;
return 0;
}