回文翼素数 - Mathematica

问题描述 投票:0回答:3

定义: 回文翼素数(或简称 PWP)是以下数字: 是素数,以 10 为基数的回文,由一个中心数字组成 被两个具有相同数量的相同数字的翅膀包围,并且 与中央不同。例如

101 99999199999 333333313333333 7777777777772777777777777 1111111111111111111111111111111141111111111111111111111111111111

如果一个数既是回文翼又是素数,那么它就是回文翼素数。以下是前几个回文翼素数: 101, 131, 151, 181, 191, 313, 353, 373, 383, 727, 757, 787, 797, 919, 929, 11311, 11411, 33533, 77377, 77477, 77977, 111411 1、1117111、3331333、3337333、 7772777, 7774777, 7778777, 111181111, 111191111, 777767777, 77777677777,...

如果一个数字是回文翼,我需要帮助找到正确的算法或伪代码 如果有人可以帮助我指导我了解有关回文翼质数、它们的历史和最后结果的更多信息,并且也许可以帮助我进行“数学编程”,那就太棒了

亲切的问候

numbers wolfram-mathematica primes
3个回答
1
投票

使用 Mathematica 测试翼长度为 1 到 20 的翼回文。

sets = DeleteCases[Tuples[Range[0, 9], 2], {a_, a_} | {0, _}];

grow[n_] := Map[Flatten, {a = ConstantArray[#1, n], #2, a} & @@@ sets]

test[c_] := If[PrimeQ[k = FromDigits@c], AppendTo[output, k]]

run[from_, to_] := Do[test /@ grow[i], {i, from, to}]

output = {};
run[1, 20]
101
131
151
181
191
...
111111111111111111131111111111111111111
777777777777777777797777777777777777777
77777777777777777777977777777777777777777

0
投票

有趣的定义,我第一次听说。

假设你知道如何检查一个数字是否是回文和素数,这里有一些伪代码和Python代码

isPalindromicWing(N){
    if isPalindromic(N){
        num <- toString(N)
        tam <- length(num)
        if isOdd(tam) and lenght(toSet(num)) = 2{
            middle <- num[ floor(tam/2) ] 
            if 1 = num.count(middle){
                return True
            }
        }
     }
     return False
}

isPWP(N){
    return isPalindromicWing(N) and isPrime(N)
}

我使用集合来删除重复,并且由于数字只能有 2 个不同的数字,因此我检查了这一点,然后我取出中间的数字并检查数字中是否只有其中一个。其余的我认为是不言自明的。


在Python中就是

lenght(toSet(num)) == 2

我不知道“mathematica 编程”,但是你理解这段代码吗?你肯定也可以做到这一点


0
投票

源代码位于

PWP100.java

def isPalindromic(N): num = str(N) return N == int( num[::-1] ) def isPalindromicWing(n): if isPalindromic(n): num = str(n) tam = len(num) if tam % 2 == 1 and len(set(num)) == 2: middle = num[tam // 2] if 1 == num.count(middle): return True return False

© www.soinside.com 2019 - 2024. All rights reserved.