题意:如果一个n位数恰好使用了1至n每个数字各一次,我们就称其为全数字的.例如,2143就是一个4位全数字数,同时它恰好也是一个素数. 最大的全数字的素数是多少? 思路: 最大全排列素数可以从 n = 9 使用 perv_permutation 倒序生成. 当 n = 9 或者 n = 8 时生成的全排列构成的数一定不是素数,因为它一定能被 3 整除,所以从 7 开始枚举. 因为生成的数字太大,所以采用米勒测试判断素数. /************************************…
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? #include <iostream> #incl…
Pandigital Fibonacci ends The Fibonacci sequence is defined by the recurrence relation: F[n] = F[n-1] + F[n-2], where F[1] = 1 and F[2] = 1. It turns out that F541, which contains 113 digits, is the first Fibonacci number for which the last nine digi…
题意: 素数41可以写成六个连续素数的和: 41 = 2 + 3 + 5 + 7 + 11 + 13 在小于一百的素数中,41能够被写成最多的连续素数的和. 在小于一千的素数中,953能够被写成最多的连续素数的和,共包含连续21个素数. 在小于一百万的素数中,哪个素数能够被写成最多的连续素数的和? 思路:首先打出100000以内的素数表,然后计算出所有从第一个素数到 j 的和,然后枚举两个端点判断是否符合要求即可 /****************************************…
Prime power triples The smallest number expressible as the sum of a prime square, prime cube, and prime fourth power is 28. In fact, there are exactly four numbers below fifty that can be expressed in such a way: 28 = 22 + 23 + 2433 = 32 + 23 + 2449…
原题: Prime summations It is possible to write ten as the sum of primes in exactly five different ways: 7 + 35 + 55 + 3 + 23 + 3 + 2 + 22 + 2 + 2 + 2 + 2 What is the first value which can be written as the sum of primes in over five thousand different…
素数线性筛 MAXN = 110100 prime = [0 for i in range(210000)] for i in range(2,MAXN): if prime[i] == 0: prime[0] += 1 prime[prime[0]] = i j = 1 while j <= prime[0] and prime[j]<=MAXN/i: prime[prime[j]*i] = 1 if i%prime[j] == 0: break j += 1 print prime[100…
题意: 将192分别与1.2.3相乘: 192 × 1 = 192192 × 2 = 384192 × 3 = 576 连接这些乘积,我们得到一个1至9全数字的数192384576.我们称192384576为192和(1,2,3)的连接乘积. 同样地,将9分别与1.2.3.4.5相乘,得到1至9全数字的数918273645,即是9和(1,2,3,4,5)的连接乘积. 对于n > 1,所有某个整数和(1,2, - ,n)的连接乘积所构成的数中,最大的1至9全数字的数是多少? /**********…
题意:找出所有形如 39 × 186 = 7254 这种,由 1 - 9,9个数字构成的等式的和,注意相同的积不计算两次 思路:如下面两种方法 方法一:暴力枚举间断点 /************************************************************************* > File Name: euler032.cpp > Author: WArobot > Blog: http://www.cnblogs.com/WArobot/ >…
题意: 欧拉发现了这个著名的二次多项式: f(n) = n2 + n + 41 对于连续的整数n从0到39,这个二次多项式生成了40个素数.然而,当n = 40时402 + 40 + 41 = 40(40 + 1) + 41能够被41整除,同时显然当n = 41时,412 + 41 + 41也能被41整除. 随后,另一个神奇的多项式n2 − 79n + 1601被发现了,对于连续的整数n从0到79,它生成了80个素数.这个多项式的系数-79和1601的乘积为-126479. 考虑以下形式的二次多…