- 注册时间
- 2014-6-29
- 最后登录
- 1970-1-1
- 威望
- 星
- 金币
- 枚
- 贡献
- 分
- 经验
- 点
- 鲜花
- 朵
- 魅力
- 点
- 上传
- 次
- 下载
- 次
- 积分
- 1361
- 在线时间
- 小时
|
发表于 2025-3-5 09:56:10
|
显示全部楼层
目前程序。无心说逆序函数有得优化。
- #include <stdio.h>
- #include <vector>
- #include <algorithm>
- #include <omp.h>
- #include <mutex>
- typedef unsigned int hword;
- typedef int shword;
- typedef unsigned long long word;
- typedef __uint128_t dword;
- constexpr word pow10(int n) {
- return n?10*pow10(n-1):1;
- }
- const int N = 13;
- const hword HALFLENU = pow10((1+N)/2);
- const hword HALFLEND = pow10(N/2);
- template<int i>
- word Reverse(word x, word y = 0) {
- return Reverse<i-1>(x/10, y*10+x%10);}
- template<>
- word Reverse<0>(word x, word y) {
- return y;}
- template<class T>
- T exgcd(T a, T b, T& x, T& y) {
- if (b == 0) {
- x = 1, y = 0;
- return a; }
- T g = exgcd(b, a%b, y, x);
- y -= a / b * x;
- return g; }
- struct COutput {
- word x;
- dword y;
- COutput(word x, dword y): x(x), y(y) {}
- COutput(): x(0), y(0) {}
- bool operator< (const COutput& o) const {
- return y < o.y; }
- };
- void Output(word* buf, int n) {
- std::sort (buf, buf+n);
- static std::mutex mu;
- std::lock_guard<std::mutex> lk(mu);
- {for (int i=0; i<n; ++i) {
- printf ("%llu ", buf[i]); }
- putchar('\n');}
- }
- std::vector<COutput> scan(hword bottom) {
- std::vector<COutput> Ret;
- for (hword i=1; i<HALFLEND; ++i) if(i%10) {
- shword x, y;
- hword g = exgcd((shword)i, (shword)HALFLEND, x, y);
- if (bottom % g) continue; // if (i==24221) fprintf(stderr, "%d!%d\n", x,g);
- // ix=g (mod HALFLEN)
- shword step = HALFLEND / g;
- x %= step; //if (i==24221 || i==23331 || i==42412 || i==26304) fprintf(stderr, "%d!%d\n", x,g);
- if (x<0) x += step;
- word Ri = Reverse<(1+N)/2>(i) * HALFLEND;
- hword j = (word)x * (bottom/g) % step;
- // while (j<i) j += step;
- j += (i-j+step-1)/step*step;
- for (; j<HALFLEND; j+=step) if(j%10)
- for (hword mid = 0; mid < HALFLENU; mid += HALFLEND) {
- word Rj = Reverse<N/2>(j) * HALFLENU;
- word RiFj = Ri + j + mid;
- word RjFi = Rj + i + mid; //if (i==2693) fprintf(stderr, "%d!%d!%lld %lld!%.8e**%d\n", j, i, RiFj, RjFi, (double)RiFj * RjFi, step);
- Ret.emplace_back(RiFj, (dword)RiFj * RjFi);
- }
- }
- std::sort(Ret.begin(), Ret.end());
- Ret.emplace_back();
- dword last = 0;
- word buffer[256];
- int curN = 0;
- for (COutput& p: Ret) {
- if (p.y != last) {
- if (curN > 1) {
- Output(buffer, curN); }
- curN = 0;
- last = p.y;
- }
- buffer[curN++] = p.x; }
- return Ret;
- }
- int cnt = 0;
- int main() {
- omp_set_num_threads(10);
- #pragma omp parallel for schedule(guided)
- for (int i=0; i<HALFLEND; i+=10) {
- fprintf(stderr, "%d\r", ++cnt);
- scan(i); }
- }
复制代码 |
|