Skip to content
Snippets Groups Projects
Commit 08c5c6d0 authored by Daniel Mario Reynaldi's avatar Daniel Mario Reynaldi
Browse files

ntt

parent 40320fe4
Branches
Tags
No related merge requests found
#include "ntt.h"
int NTT::modExp(int base, int power, int mod){
int res = 1;
int p = power;
int b = base % mod;
while (p > 0){
if (p & 1){
res = (res * b) % mod;
}
b = (b*b) % mod;
p = p >> 1;
}
return res;
}
int NTT::modInv(int x, int mod){
int t = 0;
int t1 = 1;
int r, r1 = mod, x;
while (r1 != 0){
int quot = (int) (r/r1);
int temp_t1 = t1;
int temp_t = t;
int temp_r1 = r1;
int temp_r = r;
t, t1 = t1, (t - quot * t1);
r, r1 = r1, (r % r1);
}
if (t<0){
t = t + mod;
}
return t;
}
void NTT::_ntt(vector<int64_t> &in, bool inverse){
}
vector<int64_t> NTT::ntt(Polynomial in){
vector<int64_t> out(in.degree,0);
_ntt(out, true);
return out;
}
Polynomial NTT::intt(vector<int64_t> in){
vector<int64_t> out(size(in),0);
Polynomial pOut(size(out));
int n_inv = modInv(size(out), M);
_ntt(out,false);
return pOut;
}
\ No newline at end of file
#include "polynomial.h"
#include <iostream>
#include <vector>
using namespace std;
#define size(c) ((int)(c).size())
#ifndef NTT_H
#define NTT_H
class NTT{
public:
int g = 3;
int M = 998244353;
int modExp(int base, int power, int mod);
int modInv(int x, int mod);
void _ntt(vector<int64_t> &in, bool inverse);
vector<int64_t> ntt(Polynomial in);
Polynomial intt(vector<int64_t> in);
};
#endif
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment