- 注册时间
- 2008-4-24
- 最后登录
- 1970-1-1
- 威望
- 星
- 金币
- 枚
- 贡献
- 分
- 经验
- 点
- 鲜花
- 朵
- 魅力
- 点
- 上传
- 次
- 下载
- 次
- 积分
- 2234
- 在线时间
- 小时
|
写了个随机数,然后用这个随机数验证1018*k+1是不是素数,如果是,进一步验证是不是R(509)的因子,希望碰碰运气.找到因子的概率是10^(-120),太低.
每次运行1000个素数验证的时间是200秒.
- restart;
- with(RandomTools):
- with(numtheory):
- with(FileTools):
- # ===== 全局配置 =====
- # R(509) 定义
- R509 := (10^509 - 1)/9:
- # 精度设置
- Digits := 600;
- # 计算关键边界值函数
- calcBoundary := proc(root)
- local value;
- value := evalf(R509^(1/root));
- # 精确到小数点后1位并向上取整
- return ceil(value * 10) / 10;
- end proc:
- # 预先计算边界值
- lower_small := calcBoundary(4); # R509^(1/4)
- upper_small := calcBoundary(3); # R509^(1/3)
- lower_large := upper_small; # R509^(1/3)
- upper_large := calcBoundary(2); # R509^(1/2)
- printf("小段数区间: %.1e 到 %.1e\n", lower_small, upper_small);
- printf("大段数区间: %.1e 到 %.1e\n", lower_large, upper_large);
- # 保存边界值到文件
- save lower_small, upper_small, lower_large, upper_large, "R509_boundaries.m";
- # ===== 搜索函数 =====
- searchFactors := proc(lower_bound, upper_bound, target_primes)
- local primes_found, k, p, attempts, k_lower, k_upper, start_time;
- primes_found := [];
- attempts := 0;
- start_time := time();
-
- # 计算k的范围
- k_lower := ceil((lower_bound-1)/1018);
- k_upper := floor((upper_bound-1)/1018);
-
- printf("搜索范围: k = %a 到 %a (约%.3e个可能值)\n",
- k_lower, k_upper, k_upper - k_lower + 1);
-
- # 生成候选k值直到找到目标素数数量
- while nops(primes_found) < target_primes and attempts < 10^7 do
- # 在范围内生成随机k值
- k := Generate(integer(range = k_lower..k_upper));
-
- # 添加约束条件
- # 约束1: k必须是3a+1形式
- if k mod 3 <> 1 then
- attempts := attempts + 1;
- next;
- end if;
-
- # 约束2: k的末位数字不能是3或8
- if (k mod 10 = 3) or (k mod 10 = 8) then
- attempts := attempts + 1;
- next;
- end if;
-
- # 约束3: a不能是7k+5形式 (a = (k-1)/3)
- if ((k-1)/3) mod 7 = 5 then
- attempts := attempts + 1;
- next;
- end if;
-
- # 计算候选因子 p = 1018*k + 1
- p := 1018*k + 1;
-
- # 检查p是否为素数
- if isprime(p) then
- # 添加到素数列表
- primes_found := [op(primes_found), p];
- printf("发现候选素数: %.3e (k=%a)\n", p, k);
- end if;
-
- attempts := attempts + 1;
-
- # 每10000次尝试显示进度
- if attempts mod 10000 = 0 then
- printf("尝试次数: %a, 找到素数: %d/%d\n",
- attempts, nops(primes_found), target_primes);
- end if;
- end do;
-
- printf("完成! 尝试次数: %a, 耗时: %.1f 秒\n",
- attempts, time() - start_time);
- return primes_found;
- end proc:
- # ===== 每日任务函数 =====
- dailySearch := proc()
- local large_primes, small_primes, all_candidates, factor, i, found, q;
- global day_count;
- local start_time, total_time;
-
- start_time := time();
-
- # 初始化day_count
- if not assigned(day_count) then
- day_count := 0;
- end if;
-
- day_count := day_count + 1;
- printf("\n===== 第 %d 天搜索开始 =====\n", day_count);
-
- # 大段数区间搜索 (500个素数)
- printf("\n-- 大段数区间搜索 (目标500个素数) --\n");
- large_primes := searchFactors(lower_large, upper_large, 500);
- printf("在大段数区间找到 %d 个候选素数\n", nops(large_primes));
-
- # 小段数区间搜索 (500个素数)
- printf("\n-- 小段数区间搜索 (目标500个素数) --\n");
- small_primes := searchFactors(lower_small, upper_small, 500);
- printf("在小段数区间找到 %d 个候选素数\n", nops(small_primes));
-
- # 合并所有候选素数
- all_candidates := [op(large_primes), op(small_primes)];
- printf("\n总计候选素数: %d 个\n", nops(all_candidates));
-
- # 验证候选素数是否能整除R(509)
- found := false;
- printf("开始验证 %d 个候选因子...\n", nops(all_candidates));
- for i from 1 to nops(all_candidates) do
- factor := all_candidates[i];
-
- # 使用模幂运算验证整除性
- if Power(10, 509) mod (9*factor) = 1 then
- printf("成功! 发现因子: %a\n", factor);
- # 计算并输出另一个因子
- q := R509 / factor;
- printf("对应因子: %a\n", q);
-
- # 保存结果到文件
- save factor, q, "R509_factor_found.m";
- found := true;
- # 发现因子后可以继续或停止
- end if;
- end do;
-
- if not found then
- printf("今日未发现有效因子\n");
- end if;
-
- # 保存进度
- save day_count, "R509_progress.m";
-
- total_time := time() - start_time;
- printf("\n===== 第 %d 天搜索完成, 总耗时: %.1f 秒 =====\n", day_count, total_time);
- end proc:
- # ===== 加载进度 =====
- # 尝试加载之前的进度
- if FileTools:-Exists("R509_progress.m") then
- read "R509_progress.m";
- printf("检测到先前进度: 已执行 %d 天\n", day_count);
- end if;
- # ===== 执行每日搜索 =====
- dailySearch();
- # ===== 长期运行提示 =====
- printf("\n提示: 每天运行此脚本一次,持续一年。");
- printf("要明天继续搜索,请重新运行此脚本。\n");
复制代码
|
|