跳到正文

算法·理论

Templates

Matr1xqwq约 6 分钟
原文
文章信息与版本

文章信息

发布
2023年3月25日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 6 分钟
获赞
3

版本

  1. v1当前

FastIO

C++
#define gc() (iS == iT && (iT = (iS = ibuf) + fread(ibuf, 1, 1 << 20, stdin), iS == iT) ? EOF : *iS++)
#define pc(x) ((oT - obuf == (1 << 20)) && (fwrite(obuf, 1, 1 << 20, stdout), oT = obuf), *oT++ = x)
namespace FastIO {
	char ibuf[1 << 20], obuf[1 << 20], *iS = ibuf, *iT = ibuf, *oT = obuf;
	template <typename _Tp> inline void read(_Tp& x) {
		char c = gc(); x = 0; bool f = 0;
		for(; !std::isdigit(c); c = gc()) f |= c == '-';
		for(; std::isdigit(c); c = gc()) x = (x << 1) + (x << 3) + (c ^ 48);
		f ? x = ~x + 1 : 1;
	}
	template <typename _Tp> inline void write(_Tp x) {
		static int stk[40]; int tp = 0;
		if(x < 0) pc('-'), x = ~x + 1;
		do stk[++tp] = x % 10, x /= 10; while(x);
		while(tp) pc(stk[tp--] + '0');
	}
	inline void read(char& c) { for(c = gc(); !std::isgraph(c); c = gc()); }
	inline void read(std::string& x) { x.clear(); char c = gc(); while(!std::isgraph(c)) c = gc(); while(isgraph(c)) x.push_back(c), c = gc(); }
	inline void write(const char c) { pc(c); }
	inline void write(const std::string x) { for(const char& c : x) pc(c); }
	inline void writesp() { pc(' '); }
	inline void writeln() { pc('\n'); }
	template <typename _Tp, typename ...Args> inline void read(_Tp& x, Args& ...args) { read(x), read(args...); }
	template <typename _Tp, typename ...Args> inline void write(_Tp x, Args ...args) { write(x), pc(' '), write(args...); }
	template <typename _Tp> inline void writesp(_Tp x) { write(x), pc(' '); }
	template <typename _Tp> inline void writeln(_Tp x) { write(x), pc('\n'); }
	inline void flush() { fwrite(obuf, oT - obuf, 1, stdout); } 
}
using namespace FastIO;

指令集

C++
#pragma GCC target("abm,avx,mmx,popcnt,sse,sse2,sse3,sse4,ssse3,tune=native")

缺省源

C++
#include <bits/stdc++.h>
#define gc() (iS == iT && (iT = (iS = buf) + fread(buf, 1, 1 << 20, stdin), iS == iT) ? EOF : *iS++)
char buf[1 << 20], *iS = buf, *iT = buf;
template <typename _Tp> inline void read(_Tp& x) {
	x = 0; char c = gc(); bool f = 0;
	for(; !std::isdigit(c); c = gc()) f |= c == '-';
	for(; std::isdigit(c); c = gc()) x = x * 10 + (c - '0');
}
template <> inline void read(std::string& x) {
	x.clear(); char c = gc();
	for(; !std::isalpha(c); c = gc());
	for(; std::isalpha(c); c = gc()) x += c;
}
template <typename _Tp, typename ...Args>
inline void read(_Tp& x, Args& ...args) {
	read(x), read(args...);
}
typedef long long i64;

signed main() {
	
	return 0;
}

线筛 φ,μ\boldsymbol\varphi, \mu

C++
inline void sieve(int n) {
	phi[1] = 1, mu[1] = 1;
	rep(i, 2, n) {
		if(!vis[i]) pr[++tot] = i, phi[i] = i - 1, mu[i] = -1;
		for(int j = 1; j <= tot && 1ll * i * pr[j] <= n; j++) {
			if(i % pr[j]) {
				phi[i * pr[j]] = phi[i] * (pr[j] - 1);
				mu[i] = 0;
			} else {
				phi[i * pr[j]] = phi[i] * pr[j];
				mu[i * pr[j]] = -mu[i];
				break;
			}
		}
	}
}
原文
存档评论2 条抓取于