Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Andrew Dahl
/
Project Euler
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7fe87f74
authored
Nov 15, 2011
by
Andrew Dahl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Solved Problem 7
parent
00b91fe9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
0 deletions
7/README
7/main.cpp
7/README
0 → 100644
View file @
7fe87f74
Question:
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10 001st prime number?
Answer: 104743
7/main.cpp
0 → 100644
View file @
7fe87f74
#include <iostream>
#include <vector>
using
namespace
std
;
int
main
()
{
bool
is_prime
=
true
;
int
max
=
10001
;
vector
<
long
int
>
primes
;
primes
.
push_back
(
2
);
primes
.
push_back
(
3
);
for
(
long
int
i
=
5
;
true
;
i
+=
2
)
{
is_prime
=
true
;
for
(
int
j
=
0
;
j
<
primes
.
size
();
j
++
)
{
if
(
i
%
primes
[
j
]
==
0
)
is_prime
=
false
;
}
if
(
is_prime
)
primes
.
push_back
(
i
);
if
((
primes
.
size
())
==
max
)
{
cout
<<
i
<<
endl
;
break
;
}
}
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment