(Problem 49)Prime permutations
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'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, ...
随机推荐
- 【Android进阶学习】shape和selector的结合使用
shape和selector是Android UI设计中经常用到的,比如我们要自定义一个圆角Button,点击Button有些效果的变化,就要用到shape和selector.可以这样说,shape和 ...
- pywebkitgtk安装出现的问题
configure 文件里 print sys.prefix 等不能支持python3的原因 依据http://blog.csdn.net/jklfjsdj79hiofo/article/detail ...
- Pat(Advanced Level)Practice--1043(Is It a Binary Search Tree)
Pat1043代码 题目描写叙述: A Binary Search Tree (BST) is recursively defined as a binary tree which has the f ...
- 创建Java项目报错处理
好久没用Eclipse编写Java程序了,今天创建一个Java项目的时候,老报错,错误信息如下: Implicit super constructor Object() is undefined fo ...
- java之观察者模式
import java.util.Observable; import java.util.Observer; class House extends Observable { private ...
- Linux 中执行命令
第一步: 在txt文件(文件名为cmd_file)中写入代码:echo this is content! 第二步: 授权chmod 555 cmd_file 第三步: 运行 ./cmd_file -- ...
- JAVA泛型实现一个堆栈类
package com.xt.test; /** * 泛型实现堆栈,thinking in java中的例子 * * @author Administrator * * @param <T> ...
- 终于懂了:两个UI组件同时在操作是不可能实现的
// 目的:从某个对话框里,选择一些路径,然后用Tree自动展开这些路径,但至少需要几秒钟时间 // 问题:在这几秒钟期间,显示一个等待对话框,只能开多线程,因为后台继续要处理tree的一些事情.等待 ...
- Delphi 重启应用程序(创建Bat文件的Process)
Delphi 重启应用程序在工程主文件中加入Delay(500); //启动程序时请延时一段时间,否则只能重启一次 procedure RestartApp; var BatchFile: TextF ...
- 转:CSS Overflow 属性
原文:CSS Overflow 属性译自:The CSS Overflow Property版权所有,转载请注明出处,多谢!! 根据CSS的盒模型概念,页面中的每个元素,都是一个矩形的盒子.这些盒子的 ...