(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 ...
随机推荐
- SQL SERVER 2000/2005/2008数据库数据迁移到Oracle 10G细述
最近参与的一个系统涉及到把SQL Server 2k的数据迁移到Oracle 10G这一非功能需求.特将涉及到相关步骤列举如下供大家参考: 环境及现有资源: 1.OS: Windows 7 Enter ...
- Ninject简介(转)
1.为什么要用Ninject? Ninject是一个IOC容器用来解决程序中组件的耦合问题,它的目的在于做到最少配置.其他的的IOC工具过于依赖配置文件,需要使用assembly-qualified名 ...
- BootStrap 模态框禁用空白处点击关闭问题
模态框为信息编辑窗口,涉及好多内容,填了半天,若一不小心点了空白处,那就前功尽弃了..... 所以我们很有必要禁用鼠标点击空白处模态框关闭的功能. $('#myModal').modal({backd ...
- T-SQL语句中中括号([])的用法是什么,什么时候该用
加了[]是为了防止歧义,使计算机能识别.有些字段可能是关键字,这时候你直接用字段名就会报错,如果加了[]就可以正常执行了
- 2014.9.15HTML
<html> <title> </title> ——页面标题 <head> </head> ——网页上的控制信息 <body> ...
- .net string format
转自:http://www.cnblogs.com/jobs2/p/3948049.html 转自:http://jingyan.baidu.com/article/48206aeaf8c52f216 ...
- HTML中小问题
1.a标签不添加href这个属性时,不会出现鼠标变成手型~
- MySQL 基础学习
http://www.w3school.com.cn/sql/ 1.limit x,y 或 limit z :选取从x开始的y条数据 或 选取最开始的 z条数据 , 2.like '%N%' : ...
- python初探-数据类型
数据类型 可以使用BIF type()来查看对象的类型 数字 int float long 布尔(bool) True 机内表示1,机器识别非0 False 机内表示0,机器识别0 空值 None 字 ...
- SQL Server 内存不足引起的并发症
第一:cpu 1.内存不足就会有频繁的页面调入调出.这个过程是要有cpu的参与的.所以这个要影响cpu! 2.内存不足可能会引有用起执行计划被清除.当起次要执行时.这个就要重编译一次!