当前位置: 代码迷 >> 综合 >> 欧拉工程第37题:Truncatable primes
  详细解决方案

欧拉工程第37题:Truncatable primes

热度:96   发布时间:2023-12-13 07:15:03.0

题目链接:https://projecteuler.net/problem=37

求出11个双剪质数的和

例如:
he number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3.

思路:
1.布尔型质数数组
2.如果这个数是质数,判断左剪 数都是不是质数
3. 若是,判断右剪 数 都是不是质数
4. 若是,求和

Java代码:

package projecteuler31to40;import java.util.Date;class level37{
    void solve(){int Max_Value=1000000;int sum=0;boolean[] primes=PrimeArray(Max_Value);for(int i=10;i<Max_Value;i++){int num=i;boolean flag=true;if(primes[i]){while(num>10){num=LeftToRight(num);if(primes[num]==false){flag=false;break;}}if(primes[num]==true && flag==