版权声明:欢迎转载博客(转载时请附上原文链接^_^) https://blog.csdn.net/OneLine_/article/details/88821120
这是一个我自己埋的大坑
就是 逼着自己学习吧
(其实目前 我们队的分工也不是很明确 但确实也没人搞数学题 或者说是数论题)
(欧拉计划是从宋队长那里听说的 还是跟着大佬的脚步走 = = )
所以 开一个博客 当做一个做题记录
做一题就会更新一下 基本10题会再开一篇博客 (希望自己能坚持久一点……)
yep!
按照惯例 放一下 欧拉计划的网址: 传送门
网上还有翻译版的 大家自行百度
Problem 1
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <bitset>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int sum=0;
for (int i=2;i<1000;i++)
if (i%3==0 || i%5==0)
sum+=i;
printf("%d\n",sum);
return 0;
}
答案: 233168
Problem 2
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <bitset>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x = 1,y = 2,z=0,sum = 0;
for (int i=0;i<1050;i++)
{
if (x>4000000)
break;
z = x+y;
x = y;
y = z;
// printf("%d\n",x);
if (x%2==0)
sum += x;
}
printf("%d",sum);
return 0;
}
4613732
Problem 3
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <bitset>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int su(ll x)
{
for (ll i = 2; i <= (ll)sqrt(x); i++) {
if (x % i == 0) {
return 0;
}
}
return 1;
}
int main()
{
ll m = 600851475143;
ll n = m;
ll ans = 2;
for (ll i = 2; i < n; i++) {
if (m % i == 0) {
printf("%lld ", i);
while (m % i == 0) {
m = m / i;
}
if (su(i)) {
ans = i;
}
}
if (ans > m) {
break;
}
}
printf("%lld\n", ans);
return 0;
}
71 839 1471 6857//依次输出 素数质因数
6857
Problem 4
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <bitset>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
int maxn = 100000;
for (int i = 999; i > 100; i--)
for (int j = 999; j > 100; j--)
{
int m = i * j ;
int a = m / 100000;
int b = m / 10000 % 10;
int c = m / 1000 % 10;
int d = m / 100 % 10;
int e = m / 10 % 10;
int f = m % 10;
if (a == f && b == e && c == d && m > 100000) {
maxn = max(m,maxn);
}
}
printf("%d",maxn);
return 0;
}
906609
Problem 5
懒得写代码 直接用计算器算的
11 13 17 19都是质数 所以还要再乘一遍 而16的因子在2050里面不够 缺一个2 所以再多乘一个2
Problem 6
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <bitset>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
int sum = 0, ans = 0;
for (int i = 1; i <= 100; i++) {
sum += i * i;
ans += i;
}
printf("%d",ans*ans-sum);
return 0;
}
25164150
Problem 7
这个代码跑得有点慢 (是因为数据大 没优化)
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <bitset>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int su(int x)
{
for (int i = 2; i <= (int)sqrt(x); i++) {
if (x % i == 0) {
return 0;
}
}
return 1;
}
int main()
{
int i = 1, ans = 0;
while (ans < 10001) {
i++;
if (su(i)) {
ans++;
}
}
printf("%d\n", i);
return 0;
}
104743
Problem 8
题中所指连续四个数字 我用红色方框标出了
(起先没看懂题目意思 后来看了别人的博客 就懂了= =)
意思是这是连续的1000个数 求连续的13个数的最大乘积
【当然 乘上0就是等于0 所以我优化了一点点】
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <bitset>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll sum[100005], maxn = 0;
string m = "73167176531330624919225119674426574742355349194934"
"96983520312774506326239578318016984801869478851843"
"85861560789112949495459501737958331952853208805511"
"12540698747158523863050715693290963295227443043557"
"66896648950445244523161731856403098711121722383113"
"62229893423380308135336276614282806444486645238749"
"30358907296290491560440772390713810515859307960866"
"70172427121883998797908792274921901699720888093776"
"65727333001053367881220235421809751254540594752243"
"52584907711670556013604839586446706324415722155397"
"53697817977846174064955149290862569321978468622482"
"83972241375657056057490261407972968652414535100474"
"82166370484403199890008895243450658541227588666881"
"16427171479924442928230863465674813919123162824586"
"17866458359124566529476545682848912883142607690042"
"24219022671055626321111109370544217506941658960408"
"07198403850962455444362981230987879927244284909188"
"84580156166097919133875499200524063689912560717606"
"05886116467109405077541002256983155200055935729725"
"71636269561882670428252483600823257530420752963450";
for (int i = 0; i < 990; i++) {
sum[i] = 1;
for (int j = 0; j < 13; j++) {
sum[i] *= (m[i + j] - '0');
if (sum[i] == 0) {
break;
}
}
maxn = max(maxn, sum[i]);
}
printf("%lld", maxn);
return 0;
}
23514624000
Problem 9
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <bitset>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll a, b, c;
for (a = 1; a < 900; a++)
for (b = a + 1; b < 900; b++) {
c = 1000 - a - b;
if (a * a + b * b == c * c) {
printf("%lld\n", a * b * c);
}
}
return 0;
}
31875000
Problem 10
代码没有很好看 但还是稍微优化了一下(素数除了2都是奇数 可以一直+2 )
记得用long long存储 数据结果还是有点大的……
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <bitset>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int su(ll x)
{
for (ll i = 2; i <= (ll)sqrt(x); i++) {
if (x % i == 0) {
return 0;
}
}
return 1;
}
int main()
{
ll i=1,sum=2;
while (i<2000000)
{
i+=2;
if (su(i))
sum+=i;
}
printf("%lld\n",sum);
return 0;
}
142913828922
只写了代码 没有详细的题解 先酱紫……
欢迎评论留言或者提出不足 ^-^