-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEuler.cpp
More file actions
109 lines (72 loc) · 1.53 KB
/
Euler.cpp
File metadata and controls
109 lines (72 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <iostream>
#include<cstdlib>
#include<ctime> // access functions involving time.
#include<vector>
#include <string>
#include <algorithm>
#include "myC++\vectorStuff.h"
#include <windows.h>
using namespace std;
int main()
{
/*If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
*/
int sum = 0;
for(int i = 0;i<1000;i++)
{
if((i%3==0) || (i%5==0))
{
sum += i;
}
}
cout << sum << "\n\n";
/*
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
*/
int a = 1;
int b = 2;
int c = 0;
int evenSum = 2;
while(c<=4000000)
{
c = a + b;
if(c % 2 == 0)
{
evenSum += c;
}
a = b;
b = c;
}
std::cout << "Answer : " << evenSum;
// Setup Variables for use
int number = 2521;
bool solved = false;
int oddDivides;
//while the answer hasnt been solved yet, keep going
while(solved!=true)
{
oddDivides=0;
for(int i = 2; i < 20; i++)
{
if(number % i != 0)
{
oddDivides++;
break;
}
}
//If any of the numbers didnt have any odd divides, end the loop.
if(oddDivides==0)
{
solved=true;
}
else
number++;
}
cout << "SOLVED " << endl;
cout << number;
system("pause");
return 0;
}