(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, ...
随机推荐
- NPOI 辅助类
using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using System; using S ...
- Process Node.js 进程
Process 进程 process.argv 是命令行参数数组,第一个元素是node,第二个元素是脚本文件名,从第三个元素开始每个元素是一个运行参数. process.stdout 标准输出流 co ...
- LDAP基础
超级好的LDAP文章: Linux下基于LDAP统一用户认证的研究 : http://chenguang.blog.51cto.com/350944/285602利用LDAP实现windows和Lin ...
- C++链接库
静态链接库在程序编译链接过程中就导入lib文件并且包含在生成的exe文件里,而动态链接库DLL是在程序运行中由程序加载和卸载的,也就是说它是动态的,当然动态链接库DLL也可以静态加载当做静态来用: 静 ...
- wampserver 绑定域名(wampserver 本地域名测试配置)
一.tomact 配置虚拟主机 1.打开Apache菜单下“httpd.conf”文件: 找到“# Include conf/extra/httpd-vhosts.conf” , 把这句前面的#号去掉 ...
- 1)phpmyadmin导入数据库大小限制修改
phpmyadmin默认导入数据库文件大小为2M,但一般网站的数据库导出的文件都会超出这个限制,要导入超过2M的数据库文件就需要手动修改php.ini配置文件!最近做项目遇到这个问题,顺便记录下了解决 ...
- 关于GitHub账号及文章选题
课程:软件测试基础 姓名:胡东妮 学号:2014218028 github账号:hudongni1 文章选题:测试用例的自动生成 邮箱:dongnihu@tju.edu.cn
- Clear all username or password for login.
Open cmd.exe In command, type in: control keymgr.dll. This is go to watch the password which you rem ...
- nyist 500 一字棋
题目链接: http://acm.nyist.net/JudgeOnline/problem.php?pid=500 这太并不难,只要把情况分清楚就可以了,本人由于考虑不是很周全,WA了n次....悲 ...
- Linux同平台Oracle数据库整体物理迁移
Linux同平台数据库整体物理迁移需求:A机器不再使用,要将A机器的Oracle迁移到B机器.之前写过类似需求的文章: http://www.linuxidc.com/Linux/2015-05/11 ...