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?

题目大意:

1487, 4817, 8147这个序列,每个比前一个递增3330,而且这个序列有两个特点:1. 序列中的每个数都是质数。2. 每个四位数都是其他数字的一种排列。

1,2,3位组成的三个质数的序列中没有具有以上性质的。但是还有另外一个四位的递增序列满足这个性质。

如果将这另外一个序列的三个数连接起来,组成的12位数字是多少?

//(Problem 49)Prime permutations
// Completed on Thu, 13 Feb 2014, 15:35
// Language: C
//**********************************************
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus///**********************************************
#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>
#include<string.h>
int a[]; bool prim(int n)
{
int i;
for(i = ; i * i <= n; i++) {
if(n % i ==) return false;
}
return true;
} int cmp(const void *a, const void *b)
{
return (*(char*)a - *(char*)b);
} void init()
{
int i, j;
i = ;
j = ;
a[] = ;
while(j < ) {
if(prim(i)) {
a[j++] = i;
}
i += ;
}
} bool judge(int a, int b, int c)
{
char A[], B[], C[];
sprintf(A, "%d", a);
qsort(A, , sizeof(char), cmp);
sprintf(B, "%d", b);
qsort(B, , sizeof(char), cmp);
sprintf(C, "%d", c);
qsort(C, , sizeof(char), cmp);
if(strcmp(A, B)== && strcmp(A, C) == )
return true;
return false;
} void solve()
{
int i, b, c, d;
i = ;
init();
while(a[i++] < );
for(; i < ; i++) {
b = a[i]; c = a[i] + ; d = a[i] + ;
if(d < ) {
if(prim(b) && prim(c) && prim(d)) {
if(judge(b, c, d)) {
printf("%d %d %d\n", b, c, d);
}
}
}
} } int main()
{
solve();
return ;
}
Answer:
296962999629

(Problem 49)Prime permutations的更多相关文章

  1. (Problem 62)Cubic permutations(待续)

    The cube, 41063625 (3453), can be permuted to produce two other cubes: 56623104 (3843) and 66430125 ...

  2. (Problem 41)Pandigital prime

    We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...

  3. (Problem 70)Totient permutation

    Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...

  4. (Problem 46)Goldbach's other conjecture

    It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...

  5. (Problem 47)Distinct primes factors

    The first two consecutive numbers to have two distinct prime factors are: 14 = 2  7 15 = 3  5 The fi ...

  6. (Problem 37)Truncatable primes

    The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...

  7. (Problem 35)Circular primes

    The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...

  8. (Problem 33)Digit canceling fractions

    The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplif ...

  9. (Problem 29)Distinct powers

    Consider all integer combinations ofabfor 2a5 and 2b5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, ...

随机推荐

  1. 【OpenCV新手教程之十二】OpenCV边缘检測:Canny算子,Sobel算子,Laplace算子,Scharr滤波器合辑

    本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/25560901 作者:毛星云(浅墨) ...

  2. android开发利器--站在巨人肩膀上前行

    本文主要介绍有助于android开发的三方平台和站点. 一:开发阶段 1:SVN(一个开放源码的版本号控制系统) 团队开发没有server,代码管理就没那么方便了,推荐taocode阿里开源站点,方便 ...

  3. java自己主动生成验证码

    代码结构: web.xml <? xml version="1.0" encoding="UTF-8"?> <web-app version= ...

  4. android-带进度条的系统通知栏消息

    效果图: 主界面只有一个按钮就不上文件了 通知栏显示所用到的布局文件content_view.xml <?xml version="1.0" encoding="u ...

  5. 开源ceph管理平台inkscope部署手册

    一.前情提要 关于inkscope就不做过多介绍了,就是ceph的一个开源管理控制平台,跟ceph官方的calamary以及intel的VSM差不多一类,只是各自侧重点不一样. 相对而言,因为inks ...

  6. CSS定位深入理解 完全掌握CSS定位 相对定位和绝对定位

    其实前面的标准流和浮动流都很理解,就是定位不太好理解,特别是相对定位和绝对定位,很多刚开始学的同学不好区分.因此这里,小强老师和大家一起分享CSS定位的学习. 通过我们前面的学习,我们网页布局方法: ...

  7. Convert Sorted List to Balanced Binary Search Tree (BST)

    (http://leetcode.com/2010/11/convert-sorted-list-to-balanced-binary.html) Given a singly linked list ...

  8. Windows下提升进程权限(转)

    from: http://www.oschina.net/code/snippet_222150_19533 windows的每个用户登录系统后,系统会产生一个访问令牌(access token) , ...

  9. RTTI-CLASS

    package com.xt.test; interface Test1Interface { } interface Test2Interface { } class Test1 implement ...

  10. 理解angular中的module和injector,即依赖注入

    理解angular中的module和injector,即依赖注入 依赖注入(DI)的好处不再赘言,使用过spring框架的都知道.angularjs作为前台js框架,也提供了对DI的支持,这是java ...