问个问题:为什么这个程序内存会超过512MB
  • 板块学术版
  • 楼主DeNeRATe
  • 当前回复4
  • 已保存回复4
  • 发布时间2020/9/22 15:44
  • 上次更新2023/11/5 12:47:52
查看原帖
问个问题:为什么这个程序内存会超过512MB
38171
DeNeRATe楼主2020/9/22 15:44
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

#define LL long long
#define FOR(i,A,B) for(LL i=A;i<=B;i++)
#define BOR(i,A,B) for(LL i=A;i>=B;i--)
using namespace std;
const int MaxN=3e7+10;
const LL Mod=1e9+7,Temp=500000004;

LL Inv[MaxN]={1};
LL Fac=1,Ans,Two=1,Tot;
int Total;

inline LL Fast(LL A,LL B) {
    LL Res=1;
    while(B) {
        if(B & 1) Res=(Res*A)%Mod;
        A=(A*A)%Mod; B>>=1;
    }
    return Res;
}

int main() {
    scanf("%d",&Total);
    if(Total==1) { cout<<"0"<<endl; return 0; }
    FOR(i,1,Total) Two=Two*2%Mod,Fac=Fac*i%Mod;
    Tot=Fac*Fast(Total,Mod-2)%Mod;
    Inv[Total]=Fast(Fac,Mod-2);
    BOR(i,Total-1,0) { Inv[i]=Inv[i+1]*(i+1)%Mod; } 
    BOR(i,Total,0) {	
        Ans=(Ans+Tot*Two%Mod*1ll*Inv[i]%Mod*Inv[Total-i]%Mod*(i & 1 ? -1 : 1))%Mod;
        Two=Two*Temp%Mod;
        Tot=Tot*(2*Total-i)%Mod;
    }
    Ans=(Ans+Mod)%Mod;
    Ans=Ans*Fac%Mod;
    printf("%lld\n",Ans); 
    return 0;
}
2020/9/22 15:44
加载中...