(Problem 41)Pandigital prime

时间:2022-04-04 20:30:21

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的更多相关文章

  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&&num;39&semi;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. RoR简单的应用程序

    在dos环境下执行找到需要新建的项目路径 输入命令rails -v #查看版本号

  2. 虚拟机安装LINUX网络配置注意的问题

    1.如果你配置本地IP,不上网,网卡选项可以选择仅主机模式,如果要上网,就直接选择桥接模式,复制物理网络这个选项 2.将NET1网卡(仅主机模式)选中,然后进入下面这个配置选项   上面方框内的IP段 ...

  3. javascript2

    代码变化一:<script> function abs(){ var x; if(x>0){ return x; } else{ return -x; } } console.log ...

  4. HDU 5045 Contest

    pid=5045">主题链接~~> 做题感悟:比赛时这题后来才写的,有点小尴尬.两个人商议着写写了非常久才写出来,I want to Powerful ,I believe me ...

  5. Android项目实战(四十五):Usb转串口通讯(CH34xUARTDriver)

    需求为:手机usb接口插入一个硬件,从硬件上获取数据 例如:手机usb插入硬件A,A通过蓝牙通讯获取设备a.b的数据,作为中转站(可以做些数据处理)将数据(设备a.b产生的)传给手机程序. 设备A也可 ...

  6. 第33节:Java面向对象中的异常

    Java中的异常和错误 Java中的异常机制,更好地提升程序的健壮性 throwable为*,Error和Exception Error:虚拟机错误,内存溢出,线程死锁 Exception:Runt ...

  7. Ubuntu 使用命令行连接无线网

    一.查看可以使用的无线网: nmcli dev wifi 二.连接无线网: nmcli dev wifi connect ‘essid’(网络名称) password ‘password’(密码) 可 ...

  8. JS调用webservice服务

    webservice服务 webservice服务代码 using System; using System.Collections.Generic; using System.Linq; using ...

  9. day 30 客户端获取cmd 命令的步骤

    import subprocessimport structimport jsonfrom socket import *server=socket(AF_INET,SOCK_STREAM)serve ...

  10. 【CSAPP笔记】13&period; 链接

    下面就要进入本书的第二部分--在系统上运行程序.书的第一部分,主要是研究单个应用程序,关注的是数据类型.机器指令.程序性能.存储器系统等话题.在书的第二部分,我们继续对计算机系统的探索.现代操作系统与 ...