问题描述:
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.
There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.
How many circular primes are there below one million?
解决问题:
先记录好哪些是素数,哪些不是!
public class Problem35 {
public static final int UP = 1000000;
public static boolean[] prime = new boolean[1000000];
public static boolean IsPrime(int number) {
boolean result = true;
if (number % 2 == 0) {
result = false;
} else {
int middle = (int) Math.sqrt(number);
for (int i = 3; i <= middle; i += 2) {
if (number % i == 0) {
result = false;
break;
}
}
}
return result;
}
public static boolean IsNumber(int number) {
boolean ok = true;
int current = number;
if (!prime[number]) {
return false;
}
if(number<10)
return true;
do {
int hight = current / 10;
int low = current % 10;
current = Integer.parseInt(low + "" +hight );
// System.out.println("Current:"+current);
if (!prime[current]) {
return false;
}
} while (current != number);
return ok;
}
public static int sum() {
int result = 0;
for (int i = 2; i < UP; i++) {
}
return result;
}
public static void main(String[] args) {
long sum = 1;
Arrays.fill(prime, false);
for (int i = 3; i < UP; i++) {
if(IsPrime(i))
prime[i] = true;
}
for(int i=2; i<UP; i++){
if(IsNumber(i)){
System.out.println(i);
sum++;
}
}
System.out.println("Sum:"+sum);
}
}
分享到:
相关推荐
22.6 Alarm Function Related Problem 35 22.7 Hanging Command/Hanging IO Device 35 22.8 SPG Restart 36 22.9 SPG-OSS Connection problem 36 23. MGW related problem 37 23.1 Collect Configuration Data (CV) ...
Computer Networking: A Top-Down Approach, 6th Edition Solutions to Review Questions and Problems Version Date: May 2012 ...This document contains the solutions to review questions ...Problem 1 There...
0-1-knapsack-problem-master (35).zip
Database Systems Design, Implementation & Management, 13th-Carlos Coronel(2018)/ Chapter 7 Introduction to Structured Query Language (SQL)/ Problems/ Solution(部分)
机械臂轨迹规划
genetic algorithm evolutionary tsp problem
离线安装包,亲测可用
EMC EMI资料大全电磁兼容电磁干扰设计资料工程师必备经验资料35个合集: EMC_EMI设计秘籍.pdf EMC电子工程师必备.pdf EMC电磁兼容设计与测试案例分析.pdf EMC设计总结.pdf EMC详细的技术资料.pdf EMI Indroduct.pdf ...
REFRESHER III Percents 35 LESSON 5 Solving Word Problems Using Percents 43 LESSON 6 Solving Word Problems Using Proportions 51 LESSON 7 Solving Word Problems Using Formulas 60 Quiz 2 66 REFRESHER IV ...
The Shellcoder's Handbook 2nd Edition About the Authors vii Acknowledgments xi ...The Address Problem 27 The NOP Method 33 Defeating a Non-Executable Stack 35 Return to libc 35 Conclusion 39
2.8 Minimum Cost Cylindrical Tank Design 35 2.9 Design of Coil Springs 36 2.10 Minimum Weight Design of a Symmetric Three-Bar Truss 38 2.11 A General Mathematical Model for Optimum Design 41 2.11.1 ...
35 3.6.3 Reusable barrier non-solution #2 . . . . . . . . . . . . . . 37 3.6.4 Reusable barrier hint . . . . . . . . . . . . . . . . . . . . . 39 3.6.5 Reusable barrier solution . . . . . . . . . . ....
•(P1, P2, P3, P4, P5, P6)=(25,24,15,18,22,35) •(W1, W2, W3, W4, W5, W6) = (12, 15, 10, 8, 9, 11) (4)These items could constructed by the ramdom() function in some range, such as: (Wmin, Wmax) ...
35-搜索插入位置.md 36-有效的数独.md 38计数与说.md 39-组合-sum.md 40-组合和-ii.md 第43章 第46章 47-置换-ii.md 第48章 第49章 5个最长回文子串.md 50-powx-n.md 6字形转换.md 7-反向整数.md 9回文数101...
35 15 122 16 110 17 257 18 637 19 242 20 252 中等的 问题 力码# 解决方案 1 2 关联 2 3 3 12 关联 4 34 5 92 关联 6 1249 7 142 8 33 9 153 10 80 11 128 12 102 13 199 14 200 15 11 16 209 17 73 18 78 19 46 ...
Chapter 35. Multiscale Integration for Pattern Recognition in Neuroimaging Chapter 36. Game Theoretical Tools for Wing Design Chapter 37. Fastfood Elastic ...
3 The implication problem 22 4 Metalogical properties and anomalies 28 5 A modal interpretation of OL and OQL 32 6 An axiomatization of OL and OQL 35 7 The intractability of orthomodularity 40 8 ...
CHAPTER 35 - Randomized Graph Algorithms: Techniques and Analysis SECTION XI - Coping with NP-Completeness CHAPTER 36 - General Techniques for Combinatorial Approximation CHAPTER 37 - ε-...
1-35 Using Command-Line Functions . . . . . . . . . . . . 1-47 Cluster Data with a Self-Organizing Map . . . . . . 1-56 Defining a Problem . . . . . . . . . . . . . . . . . 1-56 vii Using the Neural ...