(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 ...
随机推荐
- Solrj日期范围查询
在做依据日期来检索的时候普通的格式化会出错,试了好多种仅仅有一种可行 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH ...
- Effective C++ 条款11
在operator=中处理"自我赋值" 什么是自我赋值,非常明显. 就是自己的值赋值给了自己.以下的代码就是自我赋值: class Widget { public: Widget& ...
- angular的那些事
angular.js是什么 AngularJS 是一个 JavaScript 框架.它可通过 <script> 标签添加到 HTML 页面. AngularJS 通过 指令 扩展了 HTM ...
- SQL学习之去重复查询
下面是一张表的数据
- Ext.Net 使用总结之GridPanel中的选中行
1.判断GridPanel中是否选中了某行 if (!GridPanel1.hasSelection()) { Ext.Msg.alert("提示", "请选择记录!&q ...
- java正则表达式,将字符串中\后的第一个字母变成大写
java正则表达式,将字符串中\后的第一个字母变成大写 例子是比较简单,注意的是java中的“\\”意义是:我要插入一个正则表达式的反斜线,所以其后面的字符有特殊有意义.所以普通反斜线应该是" ...
- 获取文件数据流+叠加byte数组(给byte数组加包头包尾)
OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "(*.mp4)|*.mp4|(*.*)|*.*"; ofd.Res ...
- window权限 及c++实现 【网摘】(转)
from : http://blog.csdn.net/zipper9527/article/details/6256459 http://www.lihuasoft.net/article/show ...
- Netty4.0学习教程
http://blog.csdn.net/u013252773/article/details/21046697 一些属性和方法介绍 http://blog.csdn.net/zxhoo/articl ...
- APM代码学习笔记1
libraries目录 传感器 AP_InertialSensor 惯性导航传感器 就是陀螺仪加速计 AP_Baro 气压计 居然支持BMP085 在我印象中APM一直用高端的MS5611 AP_Co ...