Project Euler
LzyRapX
Just For Fun .
展开
-
Problem 41 Pandigital prime (暴力set+vector)
Pandigital primeProblem 41We 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 pri原创 2016-10-30 14:38:16 · 416 阅读 · 0 评论 -
PE 71 72 73 Farey Neighbours (sequence) (farey序列)
我们假设,然后,向不等式两边加上,原创 2016-11-14 14:15:33 · 615 阅读 · 0 评论 -
PE 121 Disc game prize fund (第一类斯特林)
Disc game prize fundProblem 121A bag contains one red disc and one blue disc. In a game of chance a player takes a disc at random and its colour is noted. After each turn the disc is returned to the ba原创 2016-12-10 12:57:34 · 674 阅读 · 0 评论 -
PE 96 Su Doku (数独)
Su DokuProblem 96Su Doku (Japanese meaning number place) is the name given to a popular puzzle concept. Its origin is unclear, but credit must be attributed to Leonhard Euler who invented原创 2016-11-21 18:53:13 · 618 阅读 · 0 评论 -
PE 84 Monopoly odds (随机大模拟大富翁)
Monopoly oddsProblem 84In the game, Monopoly, the standard board is set up in the following way:GOA1CC1A2T1R1B1CH1B2B3JAILH2C1T2U1原创 2016-11-21 23:26:47 · 1595 阅读 · 0 评论 -
Problem 100 Arranged probability (丢番图方程)
Arranged probabilityProblem 100If a box contains twenty-one coloured discs, composed of fifteen blue discs and six red discs, and two discs were taken at random, it can be seen that the pr原创 2016-11-23 15:28:13 · 1540 阅读 · 0 评论 -
Problem 39 Integer right triangles (数学)
Integer right trianglesProblem 39If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.{20,48,52}, {24,45,51}原创 2016-10-30 01:15:53 · 575 阅读 · 0 评论 -
PE Problem 95 Amicable chains (分解因子和)
Amicable chainsProblem 95The proper divisors of a number are all the divisors excluding the number itself. For example, the proper divisors of 28 are 1, 2, 4, 7, and 14. As the sum of thes原创 2016-11-25 21:26:24 · 445 阅读 · 0 评论 -
PE 106 Special subset sums: meta-testing (位运算枚举子集)
Special subset sums: meta-testingProblem 106Let S(A) represent the sum of elements in set A of size n. We shall call it a special sum set if for any two non-empty disjoint subsets, B and C原创 2016-12-21 21:05:18 · 604 阅读 · 0 评论 -
PE 66 Diophantine equation(Pell方程)
Diophantine equationProblem 66Consider quadratic Diophantine equations of the form:x2 – Dy2 = 1For example, when D=13, the minimal solution in x is 6492 – 13×1802 = 1.It can be ass原创 2016-11-12 20:15:43 · 907 阅读 · 0 评论 -
Problem 50 Consecutive prime sum (线性筛)
Consecutive prime sumProblem 50The prime 41, can be written as the sum of six consecutive primes:41 = 2 + 3 + 5 + 7 + 11 + 13This is the longest sum of consecutive primes that adds to原创 2016-10-31 19:58:20 · 655 阅读 · 0 评论 -
Problem 49 Prime permutations (set + vector)
Prime permutationsProblem 49The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime, and, (ii原创 2016-10-31 19:56:50 · 409 阅读 · 0 评论 -
Problem 42 Coded triangle numbers(ifstream +getline)
Coded triangle numbersProblem 42The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangle numbers are:1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...原创 2016-10-30 15:19:17 · 384 阅读 · 0 评论 -
Problem 43 Sub-string divisibility (暴力...)
Sub-string divisibilityProblem 43The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also has a rather interestin原创 2016-10-30 15:51:19 · 612 阅读 · 0 评论 -
Problem 44 Pentagon numbers (暴力...)
Pentagon numbersProblem 44Pentagonal numbers are generated by the formula, Pn=n(3n−1)/2. The first ten pentagonal numbers are:1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...It can be see原创 2016-10-30 16:23:53 · 618 阅读 · 0 评论 -
Problem 45 Triangular, pentagonal, and hexagonal (暴力)
Triangular, pentagonal, and hexagonalProblem 45Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:TriangleTn=n(n+1)/21, 3, 6, 10, 15, .原创 2016-10-30 20:18:50 · 390 阅读 · 0 评论 -
Problem 46 Goldbach's other conjecture (暴力...)
Goldbach's other conjectureProblem 46It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square.9 = 7 + 2×1215 = 7 +原创 2016-10-31 19:51:37 · 476 阅读 · 0 评论 -
Problem 47 Distinct primes factors (分解因子)
Distinct primes factorsProblem 47The first two consecutive numbers to have two distinct prime factors are:14 = 2 × 715 = 3 × 5The first three consecutive numbers to have three distin原创 2016-10-31 19:53:12 · 827 阅读 · 0 评论 -
Problem 48 Self powers (技巧)
Self powersProblem 48The series, 11 + 22 + 33 + ... + 1010 = 10405071317.Find the last ten digits of the series, 11 + 22 + 33 + ... + 10001000.Answer:9110原创 2016-10-31 19:55:08 · 559 阅读 · 0 评论 -
PE 107 Minimal network (MST)
Minimal networkProblem 107The following undirected network consists of seven vertices and twelve edges with a total weight of 243.The same network can be represented by the matrix be原创 2016-12-24 00:14:28 · 702 阅读 · 0 评论 -
PE 104 Pandigital Fibonacci ends (数学fibonacci)
Pandigital Fibonacci endsProblem 104The Fibonacci sequence is defined by the recurrence relation:Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.It turns out that F541, which contains 113 di原创 2016-12-18 20:22:21 · 553 阅读 · 0 评论 -
Project euler 401 约数的平方和 (数论)
题意:约数的平方和6的约数有1、2、3和6。这些数的平方和是1+4+9+36=50。我们记sigma2(n)是n的所有约数的平方和。因此sigma2(6)=50.我们记SIGMA2是sigma2的和函数,也就是说SIGMA2(n)=∑sigma2(i),其中i=1~n。SIGMA2的前6项为:1、6、16、37、63和113。求SIGMA2(10原创 2017-02-27 21:41:45 · 1753 阅读 · 1 评论 -
PE 118-119 (dfs+暴力)
PE 118题解:next_permutation()+dfs就可以了代码:#includeusing namespace std;typedef long long ll;int ans=0;vectorv;int isprime(ll n){ if(n==1)return 0; for(ll i=2;i*i<=n;i++){ if(n%i==0)return 0原创 2017-02-17 23:10:16 · 573 阅读 · 0 评论 -
PE 101 Optimum polynomial(拉格朗日插值)
Optimum polynomialProblem 101If we are presented with the first k terms of a sequence it is impossible to say with certainty the value of the next term, as there are infinitely many polyno原创 2016-12-11 19:45:37 · 1122 阅读 · 0 评论 -
Project euler 100题纪念
向着400+进发...原创 2016-11-22 15:00:07 · 729 阅读 · 0 评论 -
PE 123(数论)
根据Binomial theorem,对于((pn−1)n+(pn+1)n)mod(pn)2((p_n−1)^n + (p_n+1)^n)mod (p_n)^2,其中pnp_n为第nn个素数。p1=2p_1=2。我们容易得到余数为:(n∗pn∗(−1)n−1+(−1)n+n∗pn∗(1)n−1+(1)n)mod(pn)2(n*p_n*(-1)^{n-1}+(-1)^{n}+n*p_n*(1)^{n-原创 2017-04-18 20:00:28 · 650 阅读 · 0 评论 -
PE 323 Bitwise-OR operations on random integers (概率dp)
题目链接: PE 323题意: 给你一系列32bits32bits的无符号数。 xx初始为00,然后和这一系列数进行或操作,操作了NN次,直到xx是232−12^{32}-1,其实就是xx的3232个bitsbits都是11。 求NN的数学期望。题解:概率dp。 假设dp[i]dp[i]表示有ii个bitsbits时的数学期望。 那么怎么去找这些递推关系,或者说转移方程呢? 详细说明一原创 2017-05-08 21:13:00 · 610 阅读 · 0 评论 -
PE 144 Investigating multiple reflections of a laser beam (计算几何)
Investigating multiple reflections of a laser beamProblem 144In laser physics, a "white cell" is a mirror system that acts as a delay line for the laser beam. The beam enters the cell, bou原创 2016-11-09 16:48:58 · 1322 阅读 · 0 评论 -
PE 114~117 (全是dp)
PE 114代码:#includeusing namespace std;long long dp[60];//dp[i]表示从左边某个位置 开始 到位置 i 是红块的方案数 long long solve(int n){ memset(dp,0,sizeof dp); long long ans=0; for(int i=3;i<=n;i++) { dp[i]=原创 2017-02-16 16:55:42 · 491 阅读 · 0 评论 -
PE 131 Prime cube partnership (数论)
Prime cube partnershipProblem 131There are some prime values, p, for which there exists a positive integer, n, such that the expression n3 + n2p is a perfect cube.For example, when p = 1原创 2017-01-10 22:11:12 · 601 阅读 · 0 评论 -
PE 206 Concealed Square (暴力)
Concealed SquareProblem 206Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0,where each “_” is a single digit.题解:被遮挡的平方数找出唯一一个其平方形如1_2_3_原创 2017-01-08 20:05:18 · 486 阅读 · 0 评论 -
PE 108 Diophantine reciprocals I (数论:分式个数)
PE108 分式1a+1b=1n\dfrac{1}{a}+\dfrac{1}{b}=\dfrac{1}{n}的不同个数其实就是1+d(n2)2\dfrac{1+d(n^2)}{2},其中d(n)d(n)是nn的约数个数。证明:1b=1n−1a=a−nan\dfrac{1}{b}=\dfrac{1}{n}-\dfrac{1}{a}=\dfrac{a-n}{an}==>==>b=ana−nb=\dfr原创 2016-12-24 17:15:20 · 626 阅读 · 0 评论 -
PE 233 Lattice points on a circle (数论:毕格拉斯三元组(勾股数))
Lattice points on a circle Problem 233 Let f(N) be the number of points with integer coordinates that are on a circle passing through (0,0), (N,0),(0,N), and (N,N). It can be shown that f(10000) = 3原创 2016-12-26 23:52:31 · 1220 阅读 · 0 评论 -
PE 145 How many reversible numbers are there below one-billion? (暴力)
How many reversible numbers are there below one-billion?Problem 145Some positive integers n have the property that the sum [ n + reverse(n) ] consists entirely of odd (decimal) digits. For原创 2016-12-27 19:51:39 · 553 阅读 · 0 评论 -
PE 301 Nim (Nim博弈)
NimProblem 301Nim is a game played with heaps of stones, where two players take it in turn to remove any number of stones from any heap until no stones remain.We'll consider the three-he原创 2016-12-27 20:18:35 · 408 阅读 · 0 评论 -
PE 112 Bouncy numbers (模拟)
Bouncy numbersProblem 112Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, 134468.Similarly if no digit is excee原创 2016-12-27 23:18:51 · 537 阅读 · 0 评论 -
PE 105 Special subset sums: testing (位运算枚举子集)
Special subset sums: testingProblem 105Let S(A) represent the sum of elements in set A of size n. We shall call it a special sum set if for any two non-empty disjoint subsets, B and C, the原创 2016-12-20 12:17:42 · 617 阅读 · 0 评论 -
PE 111 Primes with runs (数位dp)
Primes with runsProblem 111Considering 4-digit primes containing repeated digits it is clear that they cannot all be the same: 1111 is divisible by 11, 2222 is divisible by 22, and so on.原创 2017-01-07 22:59:49 · 433 阅读 · 0 评论 -
PE 113 Non-bouncy numbers (dp)
Non-bouncy numbersProblem 113Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, 134468.Similarly if no digit is e原创 2017-01-08 19:31:35 · 755 阅读 · 0 评论 -
PE 110 Diophantine reciprocals II (数论:分式个数)(加强版)(dfs)
PE 110题目 PE 108 题解从PE 108 我们可以知道,分式 1a+1b=1n\dfrac{1}{a}+\dfrac{1}{b}=\dfrac{1}{n} 的个数 就是1+d(n2)2\dfrac{1+d(n^2)}{2},其中d(n)d(n)是n的约数的个数。、而 PE 110 只是PE 108的加强版。用PE 108的方法 换个方式就可以了。 比如:n=2p13p25p3.....原创 2016-12-26 23:13:14 · 664 阅读 · 0 评论