mirror of
https://github.com/TheAlgorithms/C
synced 2024-12-24 03:56:52 +03:00
* Please check this solution to Q7 of Project Euler * rename file * fix code formatting * added doc * updating DIRECTORY.md * added see-also references Co-authored-by: adityasheth305 <43900942+adityasheth305@users.noreply.github.com> Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
ce263033f8
commit
23b2a290fb
@ -324,6 +324,7 @@
|
||||
* [Sol](https://github.com/TheAlgorithms/C/blob/master/project_euler/problem_6/sol.c)
|
||||
* Problem 7
|
||||
* [Sol](https://github.com/TheAlgorithms/C/blob/master/project_euler/problem_7/sol.c)
|
||||
* [Sol2](https://github.com/TheAlgorithms/C/blob/master/project_euler/problem_7/sol2.c)
|
||||
* Problem 8
|
||||
* [Sol1](https://github.com/TheAlgorithms/C/blob/master/project_euler/problem_8/sol1.c)
|
||||
* [Sol2](https://github.com/TheAlgorithms/C/blob/master/project_euler/problem_8/sol2.c)
|
||||
|
@ -1,11 +1,14 @@
|
||||
/**
|
||||
* \file
|
||||
* \brief [Problem 7](https://projecteuler.net/problem=7) solution
|
||||
* \brief [Problem 7](https://projecteuler.net/problem=7) solution.
|
||||
* @see Another version: problem_7/sol2.c
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/** Main function */
|
||||
/** Main function
|
||||
* @return 0 on exit
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
char *sieve;
|
||||
|
38
project_euler/problem_7/sol2.c
Normal file
38
project_euler/problem_7/sol2.c
Normal file
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* \file
|
||||
* \brief [Problem 7](https://projecteuler.net/problem=7) solution.
|
||||
* @see Faster version problem_7/sol.c
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
/** Main function
|
||||
* @return 0 on exit
|
||||
*/
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
int number_of_prime = 0;
|
||||
for (int i = 2;; i++)
|
||||
{
|
||||
int divisors = 0;
|
||||
for (int j = 1; j <= i; j++)
|
||||
{
|
||||
if (i % j == 0)
|
||||
{
|
||||
divisors++;
|
||||
}
|
||||
}
|
||||
if (divisors == 2)
|
||||
{
|
||||
number_of_prime++;
|
||||
if (number_of_prime == n)
|
||||
{
|
||||
printf("%d", i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user