找回密码
 欢迎注册
楼主: 无心人

[讨论] 来点简单的,素性测试相关小问题

[复制链接]
 楼主| 发表于 2019-9-28 14:12:00 | 显示全部楼层
最近搞定了这个问题
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2019-9-28 15:18:28 | 显示全部楼层
Julia语言的源代码
求factors的那个利用了库,但是其实很简单,可以自己实现
因为,候选的素因子是很少的,比如,低于100
否则得到的结果,不是最佳的Jacobi sum的参数选择
按照Jacobi算法的要求,
\(  N = \prod p^{p_i} \enspace   S = 2 \prod_{q-1|N } q^{v_i}  \), p, q都是素数,且\(v_i\)满足如果\(q | N\), \(v_i = p_i + 1 \)否则\(v_i = 1\)

  1. using Primes
  2. using Printf

  3. function allMul(x, y)
  4.     [i * j
  5.        for i in x
  6.            for j in y]
  7. end

  8. function calc(n, factors)
  9.     factorList = [1]
  10.     primeList = []
  11.     for (p, k) in factors
  12.         numpower = [1]
  13.         num = 1
  14.         for i in 1:k
  15.             num *= p
  16.             push!(numpower, num)
  17.         end
  18.         factorList = allMul(factorList, numpower)
  19.     end
  20.     sort!(factorList)
  21.     return factorList
  22. end

  23. function filterPrime(n, factors, factorList)
  24.     k = factors[2]
  25.     s = big(2)^big(k+2)
  26.     primeList = [(2, k + 2)]
  27.     for x in factorList
  28.         z = x + 1
  29.         if Primes.isprime(z) && (z > 2)
  30.             k = factors[z]
  31.             s *= big(z)^big(k + 1)
  32.             push!(primeList, (z, k + 1))
  33.         end
  34.     end
  35.     return log10(s), s, primeList
  36. end

  37. numbers = [
  38. 210,420,840,1260,1680,2520,3360,3780,5040
  39. ,7560,8400,10080,12600,15120,25200,30240,42840,45360,55440,60480,75600,85680,100800,110880,128520,131040,166320,
  40. 196560,257040,332640,393120,514080,655200,665280,786240,831600,917280,982800,1081080,1179360,1285200,1310400,1441440,1663200,1965600,2162160,2751840,2827440,
  41. 3326400,3341520,3603600,3931200,4324320,5654880,6652800,6683040,7207200,8648640,10810800,12972960,14414400,18378360,21621600,36756720,43243200,64864800,73513440,
  42. 86486400,113097600,122522400,129729600,147026880,172972800,183783600,216216000,220540320,245044800,273873600,294053760,302702400,367567200,514594080,551350800,
  43. 735134400,821620800,1029188160,1074427200,1102701600,1470268800,1643241600,2058376320,2148854400,2205403200,2572970400,2940537600,3491888400,3675672000,4108104000
  44. ]
  45. for n in numbers
  46.     factors = Primes.factor(n)
  47.     factorList = calc(n, factors)
  48.     digits, s, primeList = filterPrime(n, factors, factorList)
  49.     println(n, " factors = ", factors)
  50.     println( " factorList = ", factorList)
  51.     println("primes = ", primeList)
  52.     println(" s = ", s)
  53.     @printf(" digits = %.3f\n", digits)
  54.     println("========================================================");
  55. end
复制代码
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

小黑屋|手机版|数学研发网 ( 苏ICP备07505100号 )

GMT+8, 2024-11-23 17:38 , Processed in 0.020256 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表