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质数是多少?

  1. //(Problem 41)Pandigital prime
  2. // Completed on Fri, 26 Jul 2013, 13:01
  3. // Language: C11
  4. //
  5. // 版权所有(C)acutus (mail: acutus@126.com)
  6. // 博客地址:http://www.cnblogs.com/acutus/
  7. #include<stdio.h>
  8. #include<math.h>
  9. #include<string.h>
  10. #include<ctype.h>
  11. #include<stdlib.h>
  12. #include<stdbool.h>
  13.  
  14. bool isprim(int n)
  15. {
  16. int i=;
  17. if(n==) return false;
  18. for(; i*i<=n; i++)
  19. {
  20. if(n%i==) return false;
  21. }
  22. return true;
  23. }
  24.  
  25. bool pandigital(int n)
  26. {
  27. char s[],d[]={};
  28. int i=;
  29. sprintf(s,"%d",n);
  30. int len=strlen(s);
  31. while(i<len)
  32. {
  33. switch(s[i]-'')
  34. {
  35. case : d[]++;break;
  36. case : d[]++;break;
  37. case : d[]++;break;
  38. case : d[]++;break;
  39. case : d[]++;break;
  40. case : d[]++;break;
  41. case : d[]++;break;
  42. case : d[]++;break;
  43. case : d[]++;break;
  44. default: break;
  45. }
  46. i++;
  47. }
  48. for(i=; i<=len; i++)
  49. {
  50. if(d[i]!=) return false;
  51. }
  52. if(!isprim(n)) return false;
  53. else return true;
  54. }
  55.  
  56. int main()
  57. {
  58. int i=;
  59. while(i>)
  60. {
  61. if(pandigital(i))
  62. {
  63. printf("%d\n",i);
  64. break;
  65. }
  66. i=i-;
  67. }
  68. return ;
  69. }
Answer:
7652413

(Problem 41)Pandigital prime的更多相关文章

  1. (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. ...

  2. (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 ...

  3. (Problem 49)Prime permutations

    The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual ...

  4. (Problem 70)Totient permutation

    Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...

  5. (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 ...

  6. (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 ...

  7. (Problem 37)Truncatable primes

    The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...

  8. (Problem 35)Circular primes

    The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...

  9. (Problem 57)Square root convergents

    It is possible to show that the square root of two can be expressed as an infinite continued fractio ...

随机推荐

  1. Android自定义Activity酷炫的动画跳转效果

    两个Activity跳转的时候,自定义翻页效果: Intent intent = new Intent(FirstActivity.this, SecondActivity.class);   sta ...

  2. Oracle死锁。

    oracle数据库死锁一般情况下在oracle数据库中不会.但是在程序中可以开启事物没有提交,但是程序报错我们就关了程序在重新调试.但是我们程序总是在执行 comm.ExecuteNonQuery() ...

  3. BootStrap 模态框禁用空白处点击关闭问题

    模态框为信息编辑窗口,涉及好多内容,填了半天,若一不小心点了空白处,那就前功尽弃了..... 所以我们很有必要禁用鼠标点击空白处模态框关闭的功能. $('#myModal').modal({backd ...

  4. .cs文件与aspx.cs文件之间的区别是什么???他们的作用是什么???ASPX文件的作用是什么?

    一般在vs里面新建一个页面会产生两种文件:一种是后缀名为.cs的,一种是.aspx. 简单的说,.cs文件一般是在里面实现功能的,而.aspx就是实现界面效果的. 区别:.cs文件里面写的是.net的 ...

  5. U盘安装CentOS6.x报错:Missing ISO 9660 Image

    以前都是DVD安装CentOS,这次因为装固态硬盘,然后把光驱给卸载了.所以就尝试用U盘引导安装CentOS,结果安装时竟然出现了Missing ISO 9660 Image的错误. 解决方案: 将C ...

  6. C++/C#结构体转化-二维数组-bytes To Strings

    C++结构体 typedef struct VidyoClientRequestGetWindowsAndDesktops_ { /*! The number of application windo ...

  7. BZOJ 2762: [JLOI2011]不等式组( 平衡树 )

    对不等式变形..然后就是维护一些数, 随便找个数据结构都能写吧....用double感觉会有精度误差, 分类讨论把<改成<=了很久后弃疗了, 自己写了个分数体....然后速度就被完爆了.. ...

  8. SQL 建表 插数据

    CREATE TABLE `article` ( `id` INT() NOT NULL PRIMARY KEY auto_increment, `title` CHAR() NOT NULL, `c ...

  9. 一些特殊css

    属性 描述            outline  (轮廓)是绘制于元素周围的一条线,位于边框边缘的外围,可起到突出元素的作用. outline:#00FF00 dotted thick; 可以按顺序 ...

  10. 射频识别技术漫谈(29)——射频接口芯片TRF7960

    TRF7960系列是TI推出的载波为13.56MHz.支持ISO15693.ISO14443A/B和FeliCa协议的射频接口芯片.许多人更关心它能不能读写MF1卡片,就我的理解及实际验证,由于MF1 ...