提交记录 3302


用户 题目 状态 得分 用时 内存 语言 代码长度
darksun2010 1004. 【模板题】高精度乘法 Runtime Error 0 3.448 ms 992 KB C++ 2.19 KB
提交时间 评测时间
2018-07-12 13:20:22 2020-07-31 21:15:07
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cctype>
using namespace std;

#define oo 1000000000
#define mp make_pair
#define fi first
#define se second
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define FO(i,a,b) for(int i=a;i<=b;++i)
#define FD(i,a,b) for(int i=a;i>=b;--i)
#define FE(i,G,x) for(int i=G.h[x];i!=-1;i=G.v[i].nxt)
typedef long long LL;
typedef pair<int, int> PII;

template <class T> inline bool chkmin(T& x, T y) { return x > y ? x = y, true : false; }
template <class T> inline bool chkmax(T& x, T y) { return x < y ? x = y, true : false; }

template <class T> T reads() {
    T x = 0;
    static int f;
    static char c;
    for (f = 1; !isdigit(c = getchar()); ) if (c == '-') f = -1;
    for (x = 0; isdigit(c); c = getchar()) x = x * 10 + c - 48;
    return x * f;
}
#define read   reads<int>
#define readll reads<LL>

#define pi acos(-1)

struct comp{
    double a,b;
    comp(){}
    comp(double _a,double _b):a(_a),b(_b){}
    comp operator + (const comp& o){ return comp(a+o.a,b+o.b); }
    comp operator - (const comp& o){ return comp(a-o.a,b-o.b); }
    comp operator * (const comp& o){ return comp(a*o.a-b*o.b,a*o.b+b*o.a); }
};

int n,m,t,L,R[500005],d[500005];
comp a[500005],b[500005],c[500005];

void fft(comp* a,int x){
    FO(i,0,m-1) if(i<R[i]) swap(a[i],a[R[i]]);
    for (int s=2;s<=m;s<<=1){
        comp w0=comp(cos(2*pi/s),x*sin(2*pi/s));
        for (int k=0;k<m;k+=s){
            comp w=comp(1,0);
            FO(j,0,s/2-1){
                comp t=w*a[k+j+s/2],u=a[k+j];
                a[k+j]=u+t;a[k+j+s/2]=u-t;
                w=w*w0;
            }
        }
    }
    if (x==-1) FO(i,0,m-1) a[i].a/=m;
}
char ss[500005];
int main(void){
    n=read();t=n;m=1;
    scanf("%s",ss);FO(i,0,n-1) a[n-i-1]=comp(ss[i]-'0',0);
    scanf("%s",ss);FO(i,0,t-1) b[t-i-1]=comp(ss[i]-'0',0);
    n=n*2;t=t*2;while (m<=max(n,t)) m<<=1,L++;
    FO(i,0,m-1) R[i]=(R[i>>1]>>1)|((i&1)<<(L-1));

    fft(a,1);fft(b,1);
    FO(i,0,m-1) c[i]=a[i]*b[i];
    fft(c,-1);
    FO(i,0,m-1) d[i]=(int)(c[i].a+0.1);
    FO(i,0,m-1) { d[i+1]+=d[i]/10,d[i]%=10; if (d[i+1]) m=max(m,i)+1; }
    while (!d[m-1]) m--;
    FD(i,m-1,0) putchar(d[i]+'0');
    return 0;
}


CompilationN/AN/ACompile OKScore: N/A

Testcase #13.448 ms992 KBRuntime ErrorScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-04-18 21:14:46 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠