自定义头文件"almighty.h"
持续更新
头文件内部内容:
#ifndef _ALMIGHTY_
#define _ALMIGHTY_
#include<bits/stdc++.h>
using namespace std;
#define sd signed
#define ud unsigned
#define ct const
#define sc static
typedef int i4;
typedef long long i8;
typedef float f4;
typedef double f8;
typedef void vd;
typedef bool bl;
typedef char cr;
#define Sf scanf
#define Pf printf
#define Gc getchar
#define Up(a, b, c, d) for (a = b; a <= c; a += d)
#define Dn(a, b, c, d) for (a = b; a >= c; a -= d)
i4 read();
i4 Abs(i4);
i4 lowbit(i4);
i4 countbit(i4);
i4 qpow(i4, i4, ct i4);
i4 inv(i4, i4);
i4 gcd(i4, i4);
i4 qgcd(i4, i4);
i4 exgcd(i4, i4, i4&, i4&);
vd Swap(i4&, i4&);
#endif
函数实现:
#include"almighty.h"
i4 read() {
i4 res = 0, sgn = 0;
cr ch = Gc();
while (~ch && !isdigit(ch)) sgn |= ch == '-', ch = Gc();
while (~ch && isdigit(ch)) res = (res << 1) + (res << 3) + (ch ^ 48), ch = Gc();
return sgn ? -res : res;
}
i4 Abs(i4 x) {
i4 a = x >> 31;
return (x ^ a) - a;
}
i4 lowbit(i4 x) {
return x & (-x);
}
i4 countbit(i4 x) {
i4 count = 0;
while (x) {
x = x & (x - 1);
count ++;
}
return count;
}
i4 qpow(i4 a, i4 b, ct i4 p) {
i4 res = 1;
for (; b; b >>= 1ll, a = (i8)a * a % p)
if (b & 1)
res = (i8)res * a % p;
return res;
}
i4 inv(i4 n, i4 p) {
return qpow(n, p - 2, p);
}
i4 gcd(i4 a, i4 b) {
return !b ? a : gcd(b, a % b);
}
i4 qgcd(i4 a, i4 b) {
i4 x = __builtin_ctz(a), y = __builtin_ctz(b), z = min(x, y), k;
b >>= y;
while (a) {
a >>= x;
k = b - a;
x = __builtin_ctz(k);
if (a < b) b = a;
a = k < 0 ? -k : k;
}
return b << z;
}
i4 exgcd(i4 a, i4 b, i4 &x, i4 &y) {
if (!b) {
x = 1, y = 0;
return a;
}
i4 d = exgcd(b, a % b, x, y), t = x;
x = y, y = t - (a / b) * y;
return d;
}
vd Swap(i4 &a, i4 &b) {
a ^= b, b ^= a, a ^= b;
}
标签:typedef,ch,头文件,res,i4,return,My,define
From: https://www.cnblogs.com/vectorSpace-blog/p/17691622.html