未验证
#include<bits/stdc++.h>
using namespace std;
struct Ha //没有说负负得正。。。
{
vector<int> dat; bool neg;
inline int sz()
{
return dat.size();
}
inline int&operator[](int i)
{
return dat[i];
}
inline void resz(int n)
{
dat.resize(n);
}
friend Ha operator + (Ha a, Ha b)
{
Ha c; int len = max(a.sz(), b.sz());
a.resz(len), b.resz(len), c.resz(len+1);
for(int i=0; i<len; i++)
{
c[i]+=a[i]+b[i];
if(c[i]>=10) c[i]-=10, c[i+1]++;
}
if(!c[len]) c.resz(len);
return c;
}
friend bool operator == (Ha a, Ha b)
{
if(a.sz()^b.sz()) return 0;
for(int i=a.sz()-1; ~i; --i)
if(a[i]^b[i]) return 0;
return 1;
}
friend bool operator < (Ha a, Ha b)
{
if(a.sz()^b.sz()) return a.sz()<b.sz();
for(int i=a.sz()-1; ~i; --i)
if(a[i]^b[i]) return a[i]<b[i];
return 0;
}
friend Ha operator - (Ha a, Ha b)
{
Ha c;
if(a==b)
{
c.dat.push_back(0);
return c;
}
if(a<b)
{
swap(a,b);
c.neg = 1;
}
int len = a.sz();
b.resz(len); c.resz(len);
for(int i=0; i<len; i++)
{
c[i]+=a[i]-b[i];
if(c[i]<0) c[i]+=10, c[i+1]--;
}
while(!c[c.sz()-1]) c.dat.pop_back();
return c;
}
friend Ha operator * (Ha a, Ha b)
{
Ha c; int len = a.sz() + b.sz();
c.resz(len);
for(int i=0; i<a.sz(); i++)
for(int j=0; j<b.sz(); j++)
c[i+j] += a[i]*b[j];
for(int i=0; i<c.sz(); i++)
{
if(c[i]>10)
{
int k = c[i]/10;
c[i] -= k;
c[i+1] += k;
}
}
if(!c[len-1]) c.dat.pop_back();
return c;
}
friend Ha operator / (Ha a, int b)
{
Ha c; int len=a.sz(), t=0;
for(int i=len-1; ~i; --i)
{
t = t*10+a[i];
if(t>=10)
{
int n = t/b;
c.dat.push_back(n);
t -= n*b;
}else if(c.sz()) c.dat.push_back(0);
}
reverse(c.dat.begin(), c.dat.end());
return c;
}
void read()
{
char c=getchar();
while(c<'0'||c>'9') c=getchar();
while(c>='0'&&c<='9') dat.push_back(c&15), c=getchar();
reverse(dat.begin(), dat.end());
}
void print()
{
if(neg) printf("-");
for(int i=sz()-1; ~i; --i) printf("%d", dat[i]);
}
}a;
int main()
{
a.read();
a.print();
}
FSYの
#include<bits/stdc++.h>
#define cs const
using namespace std;
#define poly vector<int>
cs int N = 4e5 + 5;
cs double PI = acos(-1.0);
struct node{
double x, y;
node(double _x = 0, double _y = 0){ x = _x; y = _y; }
node operator + (cs node &a){ return node(x + a.x, y + a.y); }
node operator - (cs node &a){ return node(x - a.x, y - a.y); }
node operator * (cs node &a){ return node(x * a.x - y * a.y, x * a.y + y * a.x); }
}f[N], g[N];
int bit, up, rev[N];
void init(int len){
bit = 0; up = 1; while(up <= len) up <<= 1, bit++;
for(int i = 0; i < up; i++) rev[i] = (rev[i>>1]>>1) | ((i&1) << (bit-1));
}
void FFT(node *a, int typ){
for(int i = 0; i < up; i++) if(i < rev[i]) swap(a[i], a[rev[i]]);
for(int i = 1; i < up; i <<= 1){
node wn(cos(PI / i), typ * sin(PI / i));
for(int j = 0; j < up; j += (i<<1)){
node w(1, 0);
for(int k = 0; k < i; k++, w = w * wn){
node x = a[k+j], y = a[k+j+i] * w;
a[k+j] = x + y; a[k+j+i] = x - y;
}
}
}
}
struct Bignum{
poly a; int flg; // + -
#define pb push_back
friend Bignum Mul(Bignum A, Bignum B){
Bignum C;
int n = A.a.size(), m = B.a.size();
int len = n + m - 1; init(len);
for(int i = 0; i < up; i++) f[i] = g[i] = node(0, 0);
for(int i = 0; i < n; i++) f[i].x = A.a[i];
for(int i = 0; i < m; i++) g[i].x = B.a[i];
FFT(f, 1); FFT(g, 1);
for(int i = 0; i < up; i++) f[i] = f[i] * g[i];
FFT(f, -1);
for(int i = 0; i < up; i++){
int v = (int)(f[i].x / up + 0.5);
C.a.pb(v);
} C.a.resize(len); return C;
}
friend Bignum operator + (Bignum A, Bignum B){
Bignum C; int len = max(A.a.size(), B.a.size());
A.a.resize(len); B.a.resize(len); C.a.resize(len + 1);
for(int i = 0; i < len; i++){
C.a[i] += A.a[i] + B.a[i];
if(C.a[i] >= 10) C.a[i] -= 10, C.a[i + 1]++;
} if(!C.a[len]) C.a.resize(len); return C;
}
friend bool operator == (Bignum A, Bignum B){
if(A.a.size() != B.a.size()) return false;
for(int i = A.a.size() - 1; i >= 0; i--){
if(A.a[i] != B.a[i]) return false;
} return true;
}
friend bool operator < (Bignum A, Bignum B){
if(A.a.size() != B.a.size()) return A.a.size() < B.a.size();
for(int i = A.a.size() - 1; i >= 0; i--){
if(A.a[i] != B.a[i]) return A.a[i] < B.a[i];
}
}
friend Bignum operator - (Bignum A, Bignum B){
Bignum C;
if(A == B){ C.a.pb(0); return C;}
if(A < B) swap(A, B), C.flg = -1;
int len = A.a.size();
C.a.resize(len); B.a.resize(len);
for(int i = 0; i < len; i++){
C.a[i] += A.a[i] - B.a[i];
if(C.a[i] < 0) C.a[i] += 10, C.a[i + 1]--;
} while(!C.a[C.a.size() - 1]) C.a.pop_back(); return C;
}
friend Bignum operator * (Bignum A, Bignum B){
Bignum C; int len = A.a.size() + B.a.size();
if(len <= 512){
C.a.resize(len);
for(int i = 0; i < A.a.size(); i++){
for(int j = 0; j < B.a.size(); j++){
C.a[i + j] += A.a[i] * B.a[j];
}
}
}
else{ C = Mul(A, B); C.a.resize(len); }
for(int i = 0; i < C.a.size(); i++){
if(C.a[i] >= 10){
int k = C.a[i] / 10;
C.a[i] -= k * 10;
C.a[i + 1] += k;
}
} if(!C.a[len - 1]) C.a.pop_back(); return C;
}
friend int operator % (Bignum A, int b){
int nx = 0;
for(int i = A.a.size() - 1; i >= 0; i--){
nx = (nx * 10 + A.a[i]) % b;
} return nx;
}
friend Bignum operator / (Bignum A, int b){
Bignum B; int len = A.a.size(), nx = 0;
for(int i = len - 1; i >= 0; i--){
nx = nx * 10 + A.a[i];
if(nx >= b){
int k = nx / b; B.a.pb(k);
nx -= k * b;
} else if(B.a.size()) B.a.pb(0);
} reverse(B.a.begin(), B.a.end()); return B;
}
void read(){
char ch = 0;
while(!isdigit(ch)) ch = getchar();
while(isdigit(ch)) a.pb(ch - '0'), ch = getchar();
reverse(a.begin(), a.end()); // 小的位在前面
}
void print(){ if(flg == -1) putchar('-'); for(int i = a.size()-1; i >= 0; i--) cout << a[i]; }
}A, B; int x;
int main(){
A.read(); B.read();
(A + B).print(); puts("");
(A - B).print(); puts("");
(A * B).print(); puts("");
A.read(); scanf("%d", &x);
int y = A % x, ans = y;
while(y) B.a.push_back(y % 10), y /= 10; A = A - B;
(A / x).print(); puts(""); cout << ans << '\n';
return 0;
}