File tree Expand file tree Collapse file tree 3 files changed +44
-2
lines changed Expand file tree Collapse file tree 3 files changed +44
-2
lines changed Original file line number Diff line number Diff line change 324
324
* [ Sol] ( https://github.com/TheAlgorithms/C/blob/master/project_euler/problem_6/sol.c )
325
325
* Problem 7
326
326
* [ Sol] ( https://github.com/TheAlgorithms/C/blob/master/project_euler/problem_7/sol.c )
327
+ * [ Sol2] ( https://github.com/TheAlgorithms/C/blob/master/project_euler/problem_7/sol2.c )
327
328
* Problem 8
328
329
* [ Sol1] ( https://github.com/TheAlgorithms/C/blob/master/project_euler/problem_8/sol1.c )
329
330
* [ Sol2] ( https://github.com/TheAlgorithms/C/blob/master/project_euler/problem_8/sol2.c )
Original file line number Diff line number Diff line change 1
1
/**
2
2
* \file
3
- * \brief [Problem 7](https://projecteuler.net/problem=7) solution
3
+ * \brief [Problem 7](https://projecteuler.net/problem=7) solution.
4
+ * @see Another version: problem_7/sol2.c
4
5
*/
5
6
#include <stdio.h>
6
7
#include <stdlib.h>
7
8
8
- /** Main function */
9
+ /** Main function
10
+ * @return 0 on exit
11
+ */
9
12
int main (void )
10
13
{
11
14
char * sieve ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * \file
3
+ * \brief [Problem 7](https://projecteuler.net/problem=7) solution.
4
+ * @see Faster version problem_7/sol.c
5
+ */
6
+ #include <stdio.h>
7
+
8
+ /** Main function
9
+ * @return 0 on exit
10
+ */
11
+ int main ()
12
+ {
13
+ int n ;
14
+ scanf ("%d" , & n );
15
+ int number_of_prime = 0 ;
16
+ for (int i = 2 ;; i ++ )
17
+ {
18
+ int divisors = 0 ;
19
+ for (int j = 1 ; j <= i ; j ++ )
20
+ {
21
+ if (i % j == 0 )
22
+ {
23
+ divisors ++ ;
24
+ }
25
+ }
26
+ if (divisors == 2 )
27
+ {
28
+ number_of_prime ++ ;
29
+ if (number_of_prime == n )
30
+ {
31
+ printf ("%d" , i );
32
+ break ;
33
+ }
34
+ }
35
+ }
36
+
37
+ return 0 ;
38
+ }
You can’t perform that action at this time.
0 commit comments