(1)Description:
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.
Question:
Find the sum of all the multiples of 3 or 5 below 1000.

#include<iostream>
#include <vector>
using namespace std;
int main() {
int m;
cin >> m;
vector<int> v;
for (int i = 0; i < m; ++i) {
if (i % 3 == 0 || i % 5 == 0) {
v.push_back(i);
}
}
long long int sum = 0;
for (int i = 0; i < v.size(); ++i) {
sum += v[i];
}
cout << sum << endl;
return 0;
}

(2)Description: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, …
Question:By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

#include<iostream>
using namespace std;
long long int Fibonacci(int n) {
if (n == 1) return 1;
if (n == 2) return 2;
return Fibonacci(n-1)+Fibonacci(n-2);
}
int main() {
long long int sum;
for (int i = 1;; ++i) {
if (Fibonacci(i) <= 4000000 && Fibonacci(i) % 2 == 0) {
cout << Fibonacci(i) << endl;
sum += Fibonacci(i);
}
else if (Fibonacci(i) > 4000000){
break;
}
}
cout << "Hello World" << endl;
cout << sum << endl;
return 0;
}

(4)Description:A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Question:Find the largest palindrome made from the product of two 3-digit numbers.

#include <iostream>
using namespace std;
long int is_huiwen(int t, int n) {
long int m = t * n;
long int copy_m = m;
int p = 0;
while (m > 0) {
p = m%10 + p*10;
m = m/10;
}
if (p == copy_m) return p;
else return -1;
}
int main() {
long int max = 0;
long int p;
int i, j;
for (i = 100;i <= 999; i++) {
for (j = 100; j <= 999; j++) {
if ((p = is_huiwen(i, j)) > max) {
max = p;
}
}
}
cout << i << " " << j << endl;
cout << max << endl;
return 0;
}

(5)Description:2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
Question:What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

#include<iostream>
using namespace std;
int main() {
for (long long int i = 1;;++i) {
int flag = 0;
for (int j = 1; j <= 20; ++j) {
if (i % j == 0) {
flag = 1;
}
else {
flag = 0;
break;
}
}
if (flag == 1) {
cout << i << endl; break;
}
else {
continue;
}
}
return 0;
}

(6)Description:The sum of the squares of the first ten natural numbers is,

The square of the sum of the first ten natural numbers is,

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 2640.
Question:Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

#include<iostream>
#include <cmath>
using namespace std;
int main() {
int sum_sq = 0;
int sq_sum = 0;
for (int i = 1; i <= 100; ++i) {
sum_sq += pow(i, 2);
sq_sum += i;
}
cout.precision(10);
cout << pow(sq_sum, 2)-sum_sq << endl;
return 0;
}

(6)Description:By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
Question:What is the 10 001st prime number?

#include<iostream>
#include <vector>
using namespace std;
int is_prime(int m) {
int flag = 0;
for (int i = 2; i < m; i++) {
if (m % i == 0) flag = 1;
}
return flag;
}
int main() {
int i = 0;
for (int j = 2;; ++j) {
if (is_prime(j) == 0) {
cout << i << endl;
i++;
if (i == 10001) {
cout << j << endl;
break;
}
}
}
return 0;
}