- 上学路上
- 2015-06-13 15:03:11 @
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define Mod 1000000007
using namespace std;
typedef long long ll;
ll x,yy,xx,y;
//const int MAXN=1000000;
bool a[1000005]={false};
vector<int> ppn(){
vector<int> p;
p.push_back(2);
int i,j;
for(i=3;i*i<=1000005;i+=2){
if(!a[i]){
p.push_back(i);
for(j=i*i;j<=1000005;j+=i)
a[j]=true;
}
}
while(i<=1000005){
if(!a[i])
p.push_back(i);
i+=2;
}
return p;
}
int pr(int x, int p){
int s=0;
ll r=p;
while(x>=r){
s+=x/r;
r*=p;
}
return s;
}
int Pow(ll n,int k,int M){
ll s=1;
while(k){
if(k&1){
s=(s*n)%M;
}
n=(n*n)%M;
k>>=1;
}
return s;
}
int C(int n, int m){
const int M=1000000007;
vector<int> p=ppn();
ll s=1;
int nm;
for(unsigned int i=0;i<p.size() && p[i]<=n;++i){
nm=pr(n,p[i])-pr(m, p[i])-pr(n-m, p[i]);
s=(s*Pow(p[i],nm,M))%M;
}
return s;
}
ll c(ll x,ll y){
return C(x+y,x);
}
int main (){
cin>>x>>xx>>y>>yy;
ll a=c(x,y)%Mod,b=c(xx,yy)%Mod,d=c(x,yy)%Mod,e=c(xx,y)%Mod;
//printf ("%d %d %d %d\n",&a,&b,&c,&e);
ll s=(a*b-d*e)%Mod;
printf ("%I64d",s);
//while (1);
return 0;
}
大神帮忙看一看
2 条评论
-
Ten.X LV 10 @ 2015-06-16 17:34:45
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>using namespace std;
typedef long long LL;
const int MaxN = 200000 + 5, Mod = 1000000007, MN = 200000;
int x, y, xx, yy;
LL Ans;
LL Fac[MaxN];void Prepare()
{
Fac[0] = 1;
for (int i = 1; i <= MN; ++i)
Fac[i] = Fac[i - 1] * (LL)i % Mod;
}LL Pow(LL a, int b)
{
LL ret = 1, f = a;
while (b)
{
if (b & 1)
{
ret *= f;
ret %= Mod;
}
b >>= 1;
f *= f;
f %= Mod;
}
return ret;
}inline LL Inv(LL x)
{
return Pow(x, Mod - 2);
}LL C(int x, int y)
{
return Fac[x] * Inv(Fac[y]) % Mod * Inv(Fac[x - y]) % Mod;
}LL Solve(int x, int y)
{
return C(x + y, x);
}int main()
{
Prepare();
scanf("%d%d%d%d", &x, &xx, &y, &yy);
Ans = (Solve(x, y) * Solve(xx, yy) % Mod - Solve(x, yy) * Solve(xx, y) % Mod) % Mod;
Ans = (Ans + Mod) % Mod;
cout << Ans << endl;
return 0;
} -
2015-06-16 11:44:04@
大神帮忙看一看
- 1
信息
- ID
- 1943
- 难度
- 6
- 分类
- (无)
- 标签
- 递交数
- 234
- 已通过
- 59
- 通过率
- 25%
- 被复制
- 2
- 上传者