{"id":18663693,"url":"https://github.com/with-sky/hyperint","last_synced_at":"2025-04-11T21:32:27.535Z","repository":{"id":61738987,"uuid":"425166283","full_name":"With-Sky/HyperInt","owner":"With-Sky","description":"A single head file high precision integer library","archived":false,"fork":false,"pushed_at":"2023-03-10T12:20:25.000Z","size":201,"stargazers_count":22,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T19:11:15.146Z","etag":null,"topics":["cpp","high-performance-computing"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/With-Sky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-06T05:44:25.000Z","updated_at":"2024-11-21T10:50:32.000Z","dependencies_parsed_at":"2023-02-09T15:31:35.100Z","dependency_job_id":null,"html_url":"https://github.com/With-Sky/HyperInt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/With-Sky%2FHyperInt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/With-Sky%2FHyperInt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/With-Sky%2FHyperInt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/With-Sky%2FHyperInt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/With-Sky","download_url":"https://codeload.github.com/With-Sky/HyperInt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248483118,"owners_count":21111427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","high-performance-computing"],"created_at":"2024-11-07T08:19:20.705Z","updated_at":"2025-04-11T21:32:27.268Z","avatar_url":"https://github.com/With-Sky.png","language":"C++","readme":"# 关于HyperInt\r\n\r\n## 概述：HyperInt是一个单头文件的大整数库，主要通过定义 HyperInt 类计算大整数。库内hint命名空间定义了常用数学函数：复数类，FFT/IFFT，NTT/INTT，中国剩馀定理CRT，快速(带模除和不带模除)整数幂。\r\n\r\n## 计算效率分析  \r\n### 关于空间：  \r\nHyperInt通过一个32位整数数组来存储数字，即原生使用2^32进制，最大化内存空间利用率。而在转为10进制字符串或者通过10进制字符串转入的过程中，使用的fft算法将消耗大量内存，解决方法是使用print_hex()方法输出16进制数避免进制转换。\r\n\r\n### 关于时间：\r\n对于被操作的位数为M、N的两数，通过常规算法计算加减法，时间复杂度为O(max(M,N))。乘法视MN的大小而定，在调用常规乘法时为O(M\\*N)，fft和ntt为O((M+N)log(M+N))，但ntt的时间常数较大，对于特别大的数是使用karatsuba算法递归分割，单纯的karatsuba算法时间复杂度为O(n^(log3))，分割到其他算法可以处理时调用其他算法。对于除法，有长除法和牛顿迭代法，长除法在M和N较小时速度较快，为O(M\\*N)，牛顿迭代法速度取决于其内部使用的乘法速度，在使用FFT时为O(Nlog(N)log(M))(*被除数的位数是M，除数的位数是N*)，例外情况是被除数和除数有多位相似时长除法表现的速度会很快。支持多线程计算乘除法，默认关闭，取消宏MULTITHREAD的注释即可开启。其他方法的时间复杂度暂不分析~\r\n\r\n## 如何使用\r\n### 引入头文件  \r\n在程序的开头需要包含头文件  \r\n`#include \"hint.hpp\"`\r\n\r\n### 创建一个HyperInt 对象\r\n`HyperInt a(12345678); //使用整数初始化`  \r\n`HyperInt b(-12345678);`  \r\n`HyperInt c(\"12345678\");//使用字符串初始化`  \r\n`HyperInt d(\"-12345678\");`  \r\n`HyperInt e(string(\"12345678\"));//使用string字符串初始化`  \r\n`HyperInt f(string(\"-12345678\"));`  \r\n除此以外，使用 `=` 初始化也可  \r\n如 `HyperInt g = \"123456\";`整数和string同理  \r\n\r\n### 算术运算(在初始化上述变量的前提下)  \r\n`a = b + c;//加法`  \r\n`a = b - c;//减法`  \r\n`d = e * f;//乘法`  \r\n`e = d / f;//除法`\r\n`e = d % f;//模除`  \r\n`a = b.square();//a被赋值为b的平方`  \r\n`a = b.square_root();//a被赋值为b的平方根`  \r\n以及\u0026、\u0026=、|、|=、^、^=的位运算  \r\n\r\n### 逻辑比较  \r\n`bool is_bigger = HyperInt(\"200000000000000000000000\") \u003e HyperInt(\"100000000000000000000000\");//true`\r\n此外\u003e=、\u003c、\u003c=、==、!=同理\r\n\r\n### 打印输出  \r\n`HyperInt a = \"123456789123456789\";`    \r\n`string s = s.to_string()//转10进制字符串`   \r\n`string s = to_string(a)//转10进制字符串`  \r\n`a.print_hex();//以16进制打印输出`  \r\n`a.print_dec();//以10进制打印输出`   \r\n`print(a);//a的位数较小时以10进制打印输出，内部数组长度大于1000000时打印16进制数`   \r\n`cout \u003c\u003c a;//直接打印a的10进制数`  \r\n\r\n### 附加函数\r\n`HyperInt a = factrial(10000);//a被初始化为10000!`  \r\n`HyperInt b = factorial(100,50);//b被初始化为50到100的连乘，即排列数排列数A(n,m） n!/(n-m)!`  \r\n`HyperInt c = combination(100,50);//c被初始化为组合数C(n,m) n!/((n-m)!m!)`  \r\n\r\n## 性能实测\r\n### 测试平台  \r\n硬件  \r\n`CPU：AMD Ryzen 7 3700X 8-Core 八核`  \r\n`主 板：华硕 ROG STRIX B450-I GAMING`  \r\n`内 存：32 GB ( KLEVV DDR4 3600MHz )`  \r\n软件平台  \r\n`版本\tWindows 11 专业工作站版`  \r\n`版本\t21H2`  \r\n`操作系统版本\t22000.1042`  \r\n`体验\tWindows 功能体验包 1000.22000.1042.0`  \r\n\r\n`编译器：gcc version 12.1.0 (x86_64-posix-seh-rev3, Built by MinGW-W64 project)`  \r\n`编译选项：-std=c++14 -O`\r\n\r\n编译运行Main.cpp 即计算10000!、100000！、1000000！  \r\n用时分别为3.369ms、89.529ms、2368.69ms  \r\n开启多线程时间分别为3.342ms、37.459ms、679.134ms  \r\n\r\n使用Visual C++编译器速度会更快一点~  \r\n更多运算请使用者自行测试~  \r\n遇到bug可以积极反馈~  \r\n感谢支持~\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwith-sky%2Fhyperint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwith-sky%2Fhyperint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwith-sky%2Fhyperint/lists"}