ProjectEuler
一时半会儿肯定写不完,
需要挂梯子但是很全的原版:https://projecteuler.net/
不需要挂梯子但是不全的中文版:https://pe-cn.github.io/problems/
P1 Multiples of 3 or 5
暴力做就行了。
P2 Even Fibonacci Numbers
还是暴力,做就行了。但是可以更好!
研究斐波那契数列的奇偶性,发现其奇偶性的排布为奇奇偶,所以利用斐波那契数列的通项公式做求和就行了。
P3 Largest Prime Factor
筛出 \(\sqrt n\) 范围内的质数,然后不断把它除掉,剩下的如果不是一那就是个大质数。
ll ans = 1;
for (int i = 1; i <= pcnt && p[i] * p[i] <= n; i++)
{
if (n % p[i]) continue;
while (n % p[i] == 0) n /= p[i];
ans = max(ans, (ll)p[i]);
}
ans = max(ans, n);
P4 Largest Palindrome Product
暴力做就行,可以用 \(\text{string}\) 中的 to_string 来把数转化成字符串来比较。
for (int i = 999; i >= 100; i--)
{
for (int j = 999; j >= 100; j--)
{
string s = to_string(i * j);
string t = s;
reverse(t.begin(), t.end());
if (s == t) ans = max(ans, i * j);
}
}
P5 Smallest Multiple
中译中可知题目所求即为 \(\operatorname{lcm}(1,2,\dots,20)\)。
P6 Sum Square Difference
当然可以 \(O(1)\) 算,但累心。
P7 10001st Prime
直接筛,然后输出。
P8 Largest Product in a Series
直接做不就完了。
P9 Special Pythagorean Triplet
枚举 \(a,b\) 就完了。
P10 Summation of Primes
筛出来求和就完了。
P11 Largest Product in a Grid
把矩阵搞成输入就好做了啊。
哎呀 5% 的做腻了,开始看 10% 的。