(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 once. For example, 2143 is a 4-digit pandigital and is also prime.
What is the largest n-digit pandigital prime that exists?
题目大意:
如果一个数字将1到n的每个数字都使用且只使用了一次,我们将其称其为一个n位的pandigital数。例如,2143是一个4位的pandigital数,并且是一个质数。
最大的n位pandigital质数是多少?
//(Problem 41)Pandigital prime
// Completed on Fri, 26 Jul 2013, 13:01
// Language: C11
//
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus/
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<stdbool.h> bool isprim(int n)
{
int i=;
if(n==) return false;
for(; i*i<=n; i++)
{
if(n%i==) return false;
}
return true;
} bool pandigital(int n)
{
char s[],d[]={};
int i=;
sprintf(s,"%d",n);
int len=strlen(s);
while(i<len)
{
switch(s[i]-'')
{
case : d[]++;break;
case : d[]++;break;
case : d[]++;break;
case : d[]++;break;
case : d[]++;break;
case : d[]++;break;
case : d[]++;break;
case : d[]++;break;
case : d[]++;break;
default: break;
}
i++;
}
for(i=; i<=len; i++)
{
if(d[i]!=) return false;
}
if(!isprim(n)) return false;
else return true;
} int main()
{
int i=;
while(i>)
{
if(pandigital(i))
{
printf("%d\n",i);
break;
}
i=i-;
}
return ;
}
Answer:
|
7652413 |
(Problem 41)Pandigital prime的更多相关文章
- (Problem 7)10001st prime
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. ...
- (Problem 3)Largest prime factor
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 60085 ...
- (Problem 49)Prime permutations
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual ...
- (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 57)Square root convergents
It is possible to show that the square root of two can be expressed as an infinite continued fractio ...
随机推荐
- char、varchar和nvarchar的区别
首先char.varchar和nvarchar.text.ntext都是数据库中的文本数据类型,再区分区分var前缀.n前缀的区别.而text.ntext已经普遍被varchar(MAX)和nvarc ...
- 散列表的实现 -- 数据结构与算法的javascript描述 第八章
散列表(哈希表 散列是一种常用的数据存储技术,散列后的数据可以快速地插入或取用. 散列表需要一个散列值(key)来存储指定数据,取数据也是依靠此. 散列值可以依靠计算数据的 ASCII码来获得,但是这 ...
- 链表的实现 -- 数据结构与算法的javascript描述 第六章
链表 链表是由一组节点组成的集合.每个节点都使用一个对象的引用指向它的后继.指向另一个节点的引用叫做链 结构示意图 : 链表头需要我们标识 head { element:head,next:obj1 ...
- Asp.net 获取图片列表并打包下载
先引用:ICSharpCode.SharpZipLib.dll 后台代码: using System.IO; using ICSharpCode.SharpZipLib.Zip; using ICSh ...
- iOS 16进制颜色转换10进制颜色
+(UIColor *)colorWithHexString:(NSString *)coloStr{ // 检索 去下空格和换行 转成大写 NSString *cString = [[col ...
- Android应用如何开机自启动、自启动失败原因
本文主要介绍Android应用如何开机自启动.自启动失败的原因.adb命令发送BOOT_COMPLETED.问题:应用程序是否可以在安装后自启动,没有ui的纯service应用如何启动?答案马上揭晓^ ...
- WebApi服务
WCF 它利用TCP.HTTP.MSMQ等传输协议构建“契约先行”的服务.WCF最初为基于SOAP的服务而设计[xml],繁琐.冗余.慢.沉重 WebApi 基于http协议,轻量级的,支持URL路由 ...
- MySQL 用户登录与操作执行
一个用户可以不登录进Mysql 数据库,由两方面的因数决定 1.你是谁:也就是mysql 数据库中记录的用户名和密码,在SQL Server数据库,中只要求说明你是谁就可以登录了,可是mysql 不是 ...
- 安装64位Oracle 10g超详细教程
安装64位Oracle 10g超详细教程 1. 安装准备阶段 1.1 安装Oracle环境 经过上一篇博文的过程,已经完成了对Linux系统的安装,本例使用X-Manager来实现与Linux系统的连 ...
- Android开发中如何解决加载大图片时内存溢出的问题
Android开发中如何解决加载大图片时内存溢出的问题 在Android开发过程中,我们经常会遇到加载的图片过大导致内存溢出的问题,其实类似这样的问题已经屡见不鲜了,下面将一些好的解决方案分享给 ...