hdu1402A * B Problem Plus(NTT)

链接:http://acm.hdu.edu.cn/showproblem.php?pid=1402

题意:大数乘法

分析:练习下NTT。学习网站:http://blog.csdn.net/acdreamers/article/details/39026505  http://blog.miskcoo.com/2015/04/polynomial-multiplication-and-fast-fourier-transform#i-15

代码:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=50010;
const int MAX=151;
const int mod=100000000;
const int MOD1=100000007;
const int MOD2=100000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000009;
const ll INF=10000000010;
typedef double db;
typedef unsigned long long ull;
ll G=3,P=469762049,a[3*N],b[3*N],wn[25];
char s[N],t[N];
ll q_pow(ll a,ll b,ll M) {
    ll ret=1;a%=M;
    while (b) {
        if (b&1) ret=ret*a%M;
        a=a*a%M;
        b>>=1;
    }
    return ret;
}
void getwn() {
    for (int i=0;i<25;i++) wn[i]=q_pow(G,(P-1)/(1<>1,k=n>>1;i>1) {//Rader
        if (i=k) { j-=k;k>>=1; }
        if (j10) { a[n]+=a[n-1]/10;a[n-1]%=10;n++; }
    while (n>1&&!a[n-1]) n--;
    for (i=n-1;i>=0;i--) printf("%I64d", a[i]);
    printf("\n");
}
int main()
{
    getwn();
    while (scanf("%s%s", s, t)!=EOF) solve();
    return 0;
}

/*
常用费马素数P=r*2^k+1,g为P的原根
P       r       k       g
3       1       1       2
5       1       2       2
17      1	    4       3
97      3	    5       5
193     3	    6       5
257     1	    8       3
7681        15      9       17
12289       3	    12      11
40961       5	    13      3
65537       1	    16      3
786433      3	    18      10
5767169     11	    19      3
7340033     7	    20      3
23068673        11	    21      3
104857601       25	    22      3
167772161       5       25      3
469762049       7       26      3
1004535809      479     21      3
2013265921      15      27      31
2281701377      17      27      3
3221225473      3       30      5
75161927681     35      31      3
77309411329     9       33      7
*/


你可能感兴趣的:(online,judge,Hdu,数学,FFT)