首页 > 编程语言 >「闲话随笔」 C++ namespace K8He-Math version -1.0.0 is officially released!

「闲话随笔」 C++ namespace K8He-Math version -1.0.0 is officially released!

时间:2023-10-13 20:00:10浏览次数:45  
标签:__ std 1.0 K8He i32 namespace int using

C++ namespace K8He-Math version -1.0.0 is officially released!

写着玩的,不清楚是否有实用价值,看个乐就行,别 D .

有 Bug 可以自己调(

怎么用感觉比较好看出来 .

namespace MATH {
	namespace Type {
		using i32 = int;
		using i64 = long long;
		using u32 = std::uint32_t;
		using u64 = std::uint64_t;
		using vi32 = std::vector <i32>;
		using vu32 = std::vector <u32>;
		using vi64 = std::vector <i64>;
		using vu64 = std::vector <u64>;
		using pr32 = std::pair <i32, i32>;
		using pr64 = std::pair <i64, i64>;
	} // namespace Type
	using namespace Type;
	namespace Setting {
		constexpr i32 P = 998244353;
		constexpr i32 infi32 = 1 << 30;
		constexpr u32 infu32 = 1 << 31;
		constexpr i64 infi64 = 1ll << 60;
		constexpr u64 infu64 = 1ll << 63;
	} // namespace Setting
	using namespace Setting;
	i32 fpow (i32 a, i32 b, i32 ans = 1) {
		for (b += (b < 0) * (P - 1); b; a = 1ll * a * a % P, b >>= 1)
			if (b & 1) ans = 1ll * ans * a % P;
		return ans;
	} // This is fast pow. You can change the initial value.
	template<int a, const int B = 65535, const int mod = P>class LightPow {
	private:
		u32 __pow[2][B + 1];
	public:
		LightPow () {
			__pow[0][0] = 1, __pow[0][1] = a;
			for (int i = 2; i <= B; ++i) __pow[0][i] = 1ll * __pow[0][i - 1] * __pow[0][1] % P;
			__pow[1][0] = 1, __pow[1][1] = 1ll * __pow[0][B] * __pow[0][1] % P;
			for (int i = 2; i <= B; ++i) __pow[1][i] = 1ll * __pow[1][i - 1] * __pow[1][1] % P;
			return;
		}
		inline int gpow (int b) { return 1ll * __pow[0][b & B] * __pow[1][b >> 16] % P; }
	}; // O(B)-O(1) calculate a^b.
	namespace binom {
		vu32 __fac ({ 1, 1 }), __inv ({ 0, 1 }), __invf ({ 1, 1 });
		inline void __prep (i32 x) {
			static i32 i = 2;
			if (i < x) {
				for (__fac.resize (x), __inv.resize (x), __invf.resize (x); i < x; ++i) {
					__fac[i] = 1ull * __fac[i - 1] * i % P;
					__inv[i] = 1ull * (P - P / i) * __inv[P % i] % P;
					__invf[i] = 1ull * __invf[i - 1] * __inv[i] % P;
				}
			}
			return;
		} inline i32 gfac (i32 x) {
			return __prep (x + 1), __fac[x];
		} inline i32 ginv (i32 x) {
			return __prep (x + 1), __inv[x];
		} inline i32 ginvf (i32 x) {
			return __prep (x + 1), __invf[x];
		} inline i32 C (i32 n, i32 m) {
			return 1ll * gfac (n) * ginvf (n - m) % P * ginvf (m) % P;
		}
	} // namespace binom
	using binom::gfac, binom::ginv, binom::ginvf, binom::C;
	// Real time expansion, you don't need to call preprocessing functions!
	namespace LinearSieve {
		vu32 __prime, __low;
		std::vector <bool> __not_a_prime;
		inline vu32 SievePrime (int n) {
			std::vector<bool> ().swap (__not_a_prime);
			__not_a_prime = (std::vector <bool>)(n + 1, false);
			for (int i = 2; i <= n; ++i) {
				if (!__not_a_prime[i]) __prime.emplace_back (i);
				for (auto j : __prime) {
					if (i * j > n) break;
					__not_a_prime[i * j] = true;
					if (!(i % j)) break;
				}
			}
			return __prime;
		} // Obtain a vector for storing prime numbers.
		inline vi32 SieveMultiF (int n, int fp (int x), int fpk (int x)) {
			vi32 ans (n + 1, 0);
			__low = vu32 (n + 1, 0);
			__not_a_prime = (std::vector <bool>)(n + 1, false);
			for (int i = 2; i <= n; ++i) {
				if (!__not_a_prime[i]) {
					__prime.emplace_back (i);
					ans[i] = fp (i), __low[i] = i;
				}
				for (auto j : __prime) {
					if (i * j > n) break;
					__not_a_prime[i * j] = true;
					if (!(i % j)) {
						__low[i * j] = __low[i] * j;
						ans[i * j] = 1ll * fpk (__low[i * j]) * ans[i / __low[i]] % P;
						break;
					}
					ans[i] = 1ll * ans[i] * ans[j] % P, __low[i] = j;
				}
			}
			return ans;
		} // Linear sieve out product function f(x). You need to pass in two functions : f (x) (x \in P) and f (x^k) (x \in P, k).
		// But I think this function is very useless and cerebral palsy, why don't you write it yourself?
	} // namespace LinearSieve
	using LinearSieve::SievePrime, LinearSieve::SieveMultiF;
} // namespace MATH
/*
If I have time, I will add the following features, but I think it's too unlikely that I will have time.

TODO:

- exgcd
- CRT
- exCRT
- ~~Lucas~~(Go away, write it yourself)
- ~~exLucas~~(I don't want to touch this thing again in my life!)

*/

标签:__,std,1.0,K8He,i32,namespace,int,using
From: https://www.cnblogs.com/K8He/p/chat_20231013.html

相关文章

  • samtools: error while loading shared libraries: libcrypto.so.1.0.0: cannot open
     001、问题:conda安装samtools后调用出现如下报错:samtools:errorwhileloadingsharedlibraries:libcrypto.so.1.0.0:cannotopensharedobjectfile:Nosuchfileordirectory 002、解决方法(base)[root@pc1home]#find~-name"libcrypto.so.1*"##......
  • PHP命令空间namespace及use的用法实践总结
    使用namespace的目的:团队合作项目时,避免与团队其它成员新建的类发生冲突;个人负责项目时,避免前后新建的类发生冲突; 据个人理解,用到所需要的类时,需要先require或include引入,所以会发生类重定义的错误的前提是:两个相同命名的类都有被引入。目前有些php框架会自动加载(即include)所......
  • nginx 关闭TLS 1.0 TLS 1.1
    server{listen443ssl;server_namewww.XXX.com;proxy_read_timeout3600s; #设置读取超时时间ssl_certificateC:/xxxx.pem;ssl_certificate_keyC:/xxxx.key;ssl_session_cachesha......
  • Semantic Kernel .NET SDK 的 v1.0.0 Beta1 发布
    介绍SemanticKernel(SK)是一个开源的将大型语言模型(LLM)与流行的编程语言相结合的SDK,Microsoft将SemanticKernel(简称SK)称为轻量级SDK,结合了OpenAI,AzureOpenAI和HuggingFace等AILLM的集成。它使开发人员能够通过编排AI组件并将其与现有代码集成来创建AI应用。SDK提供对J......
  • C#1.0--10.0版本发布时间,.NET,VS版本,CRL版本对应关系
    前言:C#的发展已经有20多年的时间了,从2002.02月发布的C#1.0,到2022.11月发布的C#10.0版本,功能也是不断完善和强大,本人从事.NET相关技术栈开发也有15年的时间,从程序员到架构师,一路走来,头发也白了不少_实战中,获取过有国家发明专利,对微服务,分布式高并发,高可用,高伸缩系统有比较丰富的......
  • 实验1.0
    1.实验任务1源代码#include<stdio.h>intmain(){printf("oo\n");printf("<H><H>\n");printf("IIII\n");getch();return0;}运行结果 2.实验任务2源代码#include<stdio.h>intma......
  • C++ namespace User_Unauthorized version 1.0.0 is officially released
    CodenamespaceUser_Unauthorized{/***@briefThisisaheaderfileforcompetitiveprogramming.*@authorUser-Unauthorized*@version1.0.0*@date2023-10-5*/typedeflonglongvalueType;typedefstd::vector<......
  • SAP UI5 里 Namespace,Class 和 Enum 的区别
    SAPUI5是一种用于构建企业级Web应用程序的前端开发框架,它提供了丰富的UI组件和工具,以便开发者可以轻松创建现代、响应式和高性能的应用程序。在SAPUI5的API文档中,我们可以找到不同类型的树节点,包括Namespace、Class和Enum。下图的C代表Class,N代表Namespace,E代表Enum.......
  • 【11.0】Fastapi的OAuth2.0的授权模式
    【一】OAuth2.0的授权模式授权码授权模式(AuthorizationCodeGrant)隐式授权模式(ImplicitGrant)密码授权模式(ResourceOwnerPasswordCredentialsGrant)客户端凭证授权模式(ClientCredentialsGrant)【二】密码授权模式【1】FastAPI的OAuth2PasswordBearer说明......
  • 【1.0】引入
    【一】为什么新秀FastAPI火成这样介绍FastAPI有哪些突出特点,浏览官网文档中的Feasures一览【二】FastAPI的突出特点性能优越开发效率提升200%~300%直接减少约40%的人为BUG直观易学易用经简代码/代码重复率低自带API交互文档,开发成果随时交付API......