(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 ...
随机推荐
- Android自定义Activity酷炫的动画跳转效果
两个Activity跳转的时候,自定义翻页效果: Intent intent = new Intent(FirstActivity.this, SecondActivity.class); sta ...
- Oracle死锁。
oracle数据库死锁一般情况下在oracle数据库中不会.但是在程序中可以开启事物没有提交,但是程序报错我们就关了程序在重新调试.但是我们程序总是在执行 comm.ExecuteNonQuery() ...
- BootStrap 模态框禁用空白处点击关闭问题
模态框为信息编辑窗口,涉及好多内容,填了半天,若一不小心点了空白处,那就前功尽弃了..... 所以我们很有必要禁用鼠标点击空白处模态框关闭的功能. $('#myModal').modal({backd ...
- .cs文件与aspx.cs文件之间的区别是什么???他们的作用是什么???ASPX文件的作用是什么?
一般在vs里面新建一个页面会产生两种文件:一种是后缀名为.cs的,一种是.aspx. 简单的说,.cs文件一般是在里面实现功能的,而.aspx就是实现界面效果的. 区别:.cs文件里面写的是.net的 ...
- U盘安装CentOS6.x报错:Missing ISO 9660 Image
以前都是DVD安装CentOS,这次因为装固态硬盘,然后把光驱给卸载了.所以就尝试用U盘引导安装CentOS,结果安装时竟然出现了Missing ISO 9660 Image的错误. 解决方案: 将C ...
- C++/C#结构体转化-二维数组-bytes To Strings
C++结构体 typedef struct VidyoClientRequestGetWindowsAndDesktops_ { /*! The number of application windo ...
- BZOJ 2762: [JLOI2011]不等式组( 平衡树 )
对不等式变形..然后就是维护一些数, 随便找个数据结构都能写吧....用double感觉会有精度误差, 分类讨论把<改成<=了很久后弃疗了, 自己写了个分数体....然后速度就被完爆了.. ...
- SQL 建表 插数据
CREATE TABLE `article` ( `id` INT() NOT NULL PRIMARY KEY auto_increment, `title` CHAR() NOT NULL, `c ...
- 一些特殊css
属性 描述 outline (轮廓)是绘制于元素周围的一条线,位于边框边缘的外围,可起到突出元素的作用. outline:#00FF00 dotted thick; 可以按顺序 ...
- 射频识别技术漫谈(29)——射频接口芯片TRF7960
TRF7960系列是TI推出的载波为13.56MHz.支持ISO15693.ISO14443A/B和FeliCa协议的射频接口芯片.许多人更关心它能不能读写MF1卡片,就我的理解及实际验证,由于MF1 ...