`
to_zoe_yang
  • 浏览: 143296 次
  • 性别: Icon_minigender_2
  • 来自: 01
社区版块
存档分类
最新评论

Problem 49

 
阅读更多

问题描述:

 

The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime, and, (ii) each of the 4-digit numbers are permutations of one another.

There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibiting this property, but there is one other 4-digit increasing sequence.

What 12-digit number do you form by concatenating the three terms in this sequence?

 

解决问题:

 

public class Problem49 {

	public static boolean[] prime = new boolean[10000];
	
	public static boolean IsPrime(long number) {
		int begin = 2;
		int end = (int) Math.sqrt(number) + 1;
		for (int i = begin; i < end; i++) {
			if (number % i == 0)
				return false;
		}
		return true;
	}
	
	public static int[] find_prime(){
		int[] numbers = new int[5000];
		Arrays.fill(numbers, 0);
		
		int index = 0;
		for(int i=1001; i<10000; i=i+2){
			if(IsPrime(i)){
				numbers[index] = i;
				index++;
			}
		}
		return numbers;
	}
	
	public static boolean IsNumber(int number){
		int tmp = number;
		int ge = number%10;
		number = number/10;
		int shi = number%10;
		number = number/10;
		int bai = number%10;
		number = number/10;
		int qian = number;
		number = tmp;
		//1487, 4817, 8147
		int number1 = bai*1000+shi*100+qian*10+ge;
		int number2 = shi*1000+qian*100+bai*10+ge;
		System.out.println("number:"+number+",number1:"+number1+",number2:"+number2);
		if(!prime[number1]||!prime[number2]){
			return false;
		}else{
			if(number1-number==number2-number1){
				return true;
			}else{
				return false;
			}
		}
		
	}
	
	public static void main(String[] args){
		Arrays.fill(prime, false);
		for(int i=1001; i<10000; i++){
			if(IsPrime(i)){
				prime[i] = true;
			}
		}
		for(int i=1001; i<prime.length; i++){
			if(prime[i]){
				if(IsNumber(i)){
					System.out.println(i);
				}
			}
		}
	}
}

 

分享到:
评论

相关推荐

    ansys license

    vendor_info=48202f8669f6767ec431e409d0f6845b49ec9f93-1f2bfb81 \ ISSUER=LND ISSUED=20-oct-2012 ck=13 SN=7330757468@CS \ START=20-oct-2012 ``` - **产品名称**:`spacdes`(推测为ANSYS SpaceClaim的一个...

    A Sequential Bundle Method for Solving a MPEC Problem

    主题分类方面,属于2000年的AMR Subject Classification中的90C30、90C25、49M37、90C59等。 文章的这部分内容给出了数学模型和方法论的基本介绍,为后续的具体算法实现和理论分析奠定了基础。文章所提出的序列束...

    A comparison of first-year, fifth-year, and former teachers on efficacy, ego development, and problem solving

    A comparison of first-year, fifth-year, and former teachers on ...Differences in first-year (N=50), fifth-year (N=49) and former ( N = 3 0 ) teachers on measures of efficacy, ego development, and pro

    md5\82477210MD5_FastCollision_v1.0.0.5_src.zip

    MD5_STEP(FF, b, c, d, a, block[15], 0x49b40821, 22); MD5_STEP(GG, a, b, c, d, block[1], 0xf61e2562, 5); MD5_STEP(GG, d, a, b, c, block[6], 0xc040b340, 9); MD5_STEP(GG, c, d, a, b, block[11], 0x265...

    FSUPIC4.949

    -- Fixes problem with spurious "multiple actions" error in Button assignments -- Provides correct Prepar3D v3 Files path when folder not shared. -- Fixes serious error in the Lua ipc togglebits, ...

    abaqus问答集合.pdf

    1 of 49 nodes可能是由于模型中的某些节点没有正确定义法向量所引起的。The system matrix has 6276 negative eigenvalues可能是由于模型中的材料模型设置不当所引起的。1304 nodes may have incorrect normal ...

    The Little Book of Semaphores

    49 3.7.3 Exclusive queue hint . . . . . . . . . . . . . . . . . . . . . 51 3.7.4 Exclusive queue solution . . . . . . . . . . . . . . . . . . . 53 3.8 Fifo queue . . . . . . . . . . . . . . . . . . ....

    leetcode-problem:leetcode中问题的解决方案

    第49章 5个最长回文子串.md 50-powx-n.md 6字形转换.md 7-反向整数.md 9回文数101-150(数量:30) 第101章 第102章 103二叉树之字形水平遍历.md 二叉树最大深度104.md 105从预购和有序遍历构建二叉树.md 106从...

    Python for Bioinformatics 第二版,最新版

    15.4 PROBLEM THREE: MODIFY EVERY RECORD OF A FASTA FILE 319 15.4.1 Commented Source Code 320 Chapter 16 Web Application for Filtering Vector Contamination 321 16.1 PROBLEM DESCRIPTION 321 16.1.1 ...

    lrucacheleetcode-30DayChallenge_Leet:https://leetcode.com/problemset/30

    49 组字谜 56.1% 中等的 53 最大子阵列 46.2% 简单的 55 跳跃游戏 34.4% 中等的 64 最小路径和 53.8% 中等的 122 买卖股票的最佳时机 II 56.4% 简单的 124 二叉树最大路径和 33.9% 难的 136 单号 65.2% 简单的 146 ...

    LDAP error code 一览表

    **LDAP_INVALID_CREDENTIALS (49)** **描述:** 提供的凭证无效。 **处理方式:** 重新输入正确的用户名和密码。 ##### 24. **LDAP_INSUFFICIENT_ACCESS (50)** **描述:** 访问权限不足。 **处理方式:** 获取...

    C++数据抽象和问题求解(第6版).[美]Frank M. Carrano(带详细书签).pdf

    2.2.1 递归值函数:n的阶乘 49 2.2.2 箱式跟踪 52 2.3 执行动作的递归 55 2.4 递归与数组 62 2.4.1 逆置数组项 63 2.4.2 折半查找 64 2.4.3 查找数组中的最大值 68 2.4.4 查找数组中第k个最小值 69 2.5 ...

    ACM练习题——沈航计算机学院.doc

    例如,如果一方宣称得了343分,另一方是49分,由于343只能由7和49的乘积获得,而49只能由49得到,因此宣称343分的一方在撒谎,因为49分的玩家无法不踩49号气球而达到这个分数。 解题策略和知识点: - **基础算法**...

    【电子书】Digital Watermarking and Steganography(第二版)

    2.5 Properties of Steganographic and Steganalysis Systems 49 2.5.1 Embedding Effectiveness 49 2.5.2 Fidelity 50 2.5.3 Steganographic Capacity, Embedding Capacity, Embedding Efficiency, and Data ...

    一年级、五年级和前任教师在效能、自我发展和解决问题方面的比较

    A comparison of first-year, fifth-year, and former teachers on ...Differences in first-year (N=50), fifth-year (N=49) and former ( N = 3 0 ) teachers on measures of efficacy, ego development, and pro

    Dreamweaver CS4 黄金插件10-02

    49. DwZone ASP Upload V1.9.0 For Adobe Dreamweaver 50. DwZone ASP.NET Advanced Mail V1.1.6 For Adobe Dreamweaver 51. DwZone ASP.NET File Upload And Resize V1.2.3 For Adobe Dreamweaver 52. DwZone ASP...

    Dreamweaver CS4 黄金插件10-05

    49. DwZone ASP Upload V1.9.0 For Adobe Dreamweaver 50. DwZone ASP.NET Advanced Mail V1.1.6 For Adobe Dreamweaver 51. DwZone ASP.NET File Upload And Resize V1.2.3 For Adobe Dreamweaver 52. DwZone ASP...

Global site tag (gtag.js) - Google Analytics