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的更多相关文章
-
(Problem 62)Cubic permutations(待续)
The cube, 41063625 (3453), can be permuted to produce two other cubes: 56623104 (3843) and 66430125 ...
-
(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 ...
-
(Problem 70)Totient permutation
Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...
-
(Problem 46)Goldbach&#39;s other conjecture
It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...
-
(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 ...
-
(Problem 37)Truncatable primes
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...
-
(Problem 35)Circular primes
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...
-
(Problem 33)Digit canceling fractions
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplif ...
-
(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, ...
随机推荐
-
Web APi之过滤器执行过程原理解析【二】(十一)
前言 上一节我们详细讲解了过滤器的创建过程以及粗略的介绍了五种过滤器,用此五种过滤器对实现对执行Action方法各个时期的拦截非常重要.这一节我们简单将讲述在Action方法上.控制器上.全局上以及授 ...
-
LeetCode Minimum Moves to Equal Array Elements
原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements/ 题目: Given a non-empty i ...
-
转 未能加载类型 xxxx
未能加载类型 分析器错误 说明: 在分析向此请求提供服务所需资源时出错.请检查下列特定分析错误详细信息并适当地修改源文件. 分析器错误信息: 未能加载类型“xxxxx”. 错误的 < ...
-
Web - 客户端存储的几种方式
客户端存储主要方便一些APP离线使用.今天就来说说客户端存储的方法有多少? 说在最前面的一句:所有的客户端存储都有一个原则:读写的数据必须要同域 1 Cookie Cookie是一项很老的技术的,就是 ...
-
结构型模式(Structural patterns)->;外观模式(Facade Pattern)
动机(Motivate): 在软件开发系统中,客户程序经常会与复杂系统的内部子系统之间产生耦合,而导致客户程序随着子系统的变化而变化.那么如何简化客户程序与子系统之间的交互接口?如何将复杂系统的内部子 ...
-
php等号(==)与全等(===)
<?php require_once 'Person.php'; header("content-type:text/html;charset=utf-8"); $perso ...
-
nginx源代码分析--模块分类
ngx-modules Nginx 基本的模块大致能够分为四类: handler – 协同完毕client请求的处理.产生响应数据.比方模块, ngx_http_rewrite_module, ngx ...
-
[python]函数返回多个return值
python支持函数直接返回多个变量,具体用法如下: >>> def test(): ... a=2 ... b=3 ... return a,b ... >>> ...
-
-第1章 HTMLCSS方法实现下拉菜单
中英文的自动换行问题 把下面代码中的 javascript 改成 子菜单1 试试, 如果英文的话宽度会自动撑开, 用中文不会, 而直接转行下来. <ul> <li><a ...
-
C++学习(十九)(C语言部分)之 指针3
复习1.一级指针 int*p 指向int的指针 赋值 int x; p=&x;// *p=2; 指针指向的谁 解引用之后就是谁2.内存四区 堆区 需要自己手动申请内存 自己释放 (malloc ...