{"id":21359968,"url":"https://github.com/nkid00/5x5","last_synced_at":"2026-05-05T03:38:01.885Z","repository":{"id":113341717,"uuid":"345129105","full_name":"NKID00/5x5","owner":"NKID00","description":"解一个简单的数学问题。","archived":false,"fork":false,"pushed_at":"2021-06-27T07:14:09.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-22T18:52:32.270Z","etag":null,"topics":["cpp","cpp11","mathematics","python","python3"],"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/NKID00.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-06T15:38:06.000Z","updated_at":"2021-03-07T02:23:53.000Z","dependencies_parsed_at":"2023-03-13T13:20:08.041Z","dependency_job_id":null,"html_url":"https://github.com/NKID00/5x5","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NKID00%2F5x5","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NKID00%2F5x5/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NKID00%2F5x5/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NKID00%2F5x5/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NKID00","download_url":"https://codeload.github.com/NKID00/5x5/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243835951,"owners_count":20355611,"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","cpp11","mathematics","python","python3"],"created_at":"2024-11-22T05:31:37.755Z","updated_at":"2026-05-05T03:37:56.865Z","avatar_url":"https://github.com/NKID00.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1\u003e\n    \u003cp align=center\u003e\n        5x5\n    \u003c/p\u003e\n\u003c/h1\u003e\n\n\u003e 解一个简单的数学问题：\n\u003e \n\u003e 将1 至 25 的整数分别不重复地填入一个 5 行 5 列的矩阵中，求满足当 N 为 1 至 5 的整数时第 N 行数字的乘积和第 N 列数字的乘积相等的矩阵。\n\n计算得到了 26412140760 个解，输出文件约 9.198 GiB。\n\n简单分析问题可得知以下约束条件：\n\n- 左上至右下斜对角线中的数字将会同时出现在行乘积和列乘积中，这 5 个空格可以填入任意数。因此将数字排列到左上至右下斜对角线以外的 20 个空格中即可，剩余 5 个数字简单排列即可得出 120（5P5）种解。\n\n  - 已在程序中实现。\n\n- 13，17，19 和 23 这 4 个数字是质数且没有它们的倍数，只能出现在左上至右下斜对角线中。因此使用这 4 个数字以外的 21 个数字进行排列。\n\n  - 已在程序中实现。\n\n- 11 是质数且只有 22 是它的倍数。因此 11 和 22 一定会在以左上至右下斜对角线为对称轴对称的两个空格中。\n\n  - 尚未在程序中实现。\n\n- 7 是质数且只有 14 和 21 是它的倍数。因此 7，14 和 21 一定会在三个空格中，任意一个在左上至右下斜对角线上，或者其中任意一个空格的行坐标一定等于另一空格的列坐标。\n\n  - 尚未在程序中实现。\n\n- 一些 4 个数的组合的乘积在所有组合的乘积中只出现了一次。因此这些组合一定不会出现在同一行或同一列中。\n\n  - 部分在程序中实现。\n\n编写了这些程序：\n\n- `gen.py` 用于枚举所有一定不会出现在同一行或同一列中的 4 个数的排列。\n\n  - 输出到 `./data.txt`。\n\n- `5x5.cpp` 用于枚举所有符合部分约束条件的情况并测试是否满足条件。\n\n  - 多线程计算，考虑了部分约束条件，计算速度较快（在 AMD R7 4800U 上预计需要几十个小时）。\n\n  - 结果输出到 `./result.txt`，进度输出到 `stderr`。\n\n- `5x5.old.cpp` 用于枚举所有的情况并测试是否满足条件。\n\n  - 单线程计算，没有考虑约束条件，计算速度极慢（预计需要几百亿年）。可能有漏洞。\n\n  - 输出到 `stdout`。\n\n- `count.py` 用于统计解的数量。\n\n  - 从 `./result.txt` 输入，输出到 `stdout`。\n\n## 构建\n\n```shell\n$ git clone https://github.com/NKID00/5x5.git\n$ cd 5x5\n$ g++ ./5x5.cpp --std=c++11 -O3 -o ./5x5  # 构建\n$ ./5x5  # 运行\n```\n\n如果发现漏洞或者遇到问题，欢迎提交 [Issue](https://github.com/NKID00/5x5/issues) 或者 [Pull Request](https://github.com/NKID00/5x5/pulls)。\n\n## 版权\n\n版权所有 © NKID00 2021。\n\n使用 [MIT License](./LICENSE) 进行许可。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnkid00%2F5x5","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnkid00%2F5x5","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnkid00%2F5x5/lists"}