问题描述:
By replacing the 1st
digit of *3, it turns out that six of the
nine possible values: 13, 23, 43, 53, 73, and 83, are all prime.
By replacing the 3rd
and 4th
digits of 56**3 with the
same digit, this 5-digit number is the first example having seven primes among
the ten generated numbers, yielding the family: 56003, 56113, 56333, 56443,
56663, 56773, and 56993. Consequently 56003, being the first member of this
family, is the smallest prime with this property.
Find the smallest prime which, by replacing part of the number (not
necessarily adjacent digits) with the same digit, is part of an eight prime
value family.
解决问题:
package projecteuler;
import java.util.Arrays;
public class Problem51 {
public static boolean[] prime = new boolean[2000000];
public static boolean IsPrime(long number) {
for (int i = 2; i * i <= number; i++) {
if (number % i == 0)
return false;
}
return true;
}
public static void main(String[] args) {
Arrays.fill(prime, false);
for (int i = 1; i < prime.length; i++) {
if (IsPrime(i)) {
prime[i] = true;
}
}
boolean ok = true;
for (int i = 10000; i < prime.length && ok; i++) {
// int i = 56003;
if (prime[i]) {
int begin = 0;
for (begin = 0; begin < 3; begin++) {
int number = i;
int count = 0;
int count_cur = 0;
int add = 0;
number = number / 10;
while (number != 0) {
int cur = number % 10;
if (cur == begin) {
add = add * 10 + 1;
count_cur++;
} else {
add *= 10;
}
number = number / 10;
}
if (count_cur > 1) {
add *= 10;
// System.out.println("Add:"+add);
int end = 9 - begin;
int total = 1;
int tmp = i;
for (int j = 0; j < end; j++) {
tmp += add;
// System.out.println("Tmp:"+tmp);
if (prime[tmp]) {
total++;
}
}
if (total == 8) {
System.out.println("Number:" + i);
System.out.println("Add:" + add);
ok = false;
break;
}
}
}
}
}
}
}
分享到:
相关推荐
2019-51MCM-Problem A (English)
SUMS51 Mathematica -- A Problem-Centered Approach, Roozbeh Hazrat (2010) .zip
2023-51MCM-Problem B‘【 】’2023年第二十届五一数学建模竞赛题目 B题:快递需求分析问题
2020MCM——A题目
2023五一赛思路
java
周天涯
其中包括2018_MCM_ProblmomA和B和C,并且包含C题所含数据excel表格,以及2018ICM__Problem_D和E和F。
基于51单片机
储罐分配contraint base 本地搜索对象数据和问题的项目在:csplib.org number problem 51。 由java和jsp编写。 Web应用程序。
ACM学习必备资料,共有51个经典例子,word文档共126页。题目、解题思路、分析过程、源码(源码亲自运行都可过),整理并贡献出来,真心希望能给大家用上。1.河内之塔2.费式数列3. 巴斯卡三角形4.三色棋5.老鼠走迷宫...
51, 52, , , , , 57, , , , , , , , 65, , , 68, , , , , , , , 76, , , , , 81, , , 84, 85, , 87, , , , 91, , 93, , , , 97, , 99, , , , , , 105, 106, , , , , , , , , 115, 116, 117, , , , , , 123, 124, , ...
13.背包问题(Knapsack Problem) 26 14.蒙地卡罗法求 PI 31 15.Eratosthenes筛选求质数 32 16.超长整数运算(大数运算) 34 17.长 PI 36 18.最大公因数、最小公倍数、因式分解 39 19.完美数 42 20.阿姆斯壮数 45 21...
LESSON 6 Solving Word Problems Using Proportions 51 LESSON 7 Solving Word Problems Using Formulas 60 Quiz 2 66 REFRESHER IV Equations 69 LESSON 8 Algebraic Representation 82 LESSON 9 Solving Number ...
51 3.7.4 Exclusive queue solution . . . . . . . . . . . . . . . . . . . 53 3.8 Fifo queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 3.8.1 Fifo queue hint . . . . . . . . . . . ...
ChaptEr 3 Variables and Constants 51 ChaptEr 4 Completing the Problem-Solving Process 75 ChaptEr 5 The Selection Structure 113 ChaptEr 6 More on the Selection Structure 157 ChaptEr 7 The Repetition ...
现在是2020年5月4日0:51分,2020年五四青年节,我终于解决了这个问题 问题描述: 原创文章 74获赞 31访问量 7781 关注 私信 展开阅读全文 作者:GRIT_Kael
官方离线安装包,亲测可用
Problem: Building a Network 2 1.1 Applications 4 1.2 Requirements 6 1.2.1 Connectivity 7 1.2.2 Cost-Effective Resource Sharing 10 1.2.3 Support for Common Services 15 1.3 Network Architecture 19 1.3.1...