• Home
  • About
    • Moon photo

      2019 OSS E4

      E4 is a team which is made in OSS Class in 2019 1st Semester

    • Learn More
    • Twitter
    • Facebook
    • Instagram
    • Github
    • Steam
  • Posts
    • All Posts
    • All Tags
  • Projects

Project Euler Prob.5

10 Jun 2019

Reading time ~1 minute

Problem

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

Sol. 1

#include <stdio.h>
using namespace std;
int main()
{
	int arr[21] = { 0, };
	int v = 1;
	for (int i = 2; i <= 20; i++)
	{
		if (arr[i] == 0)
		{
			int s = i;
			while (s <= 20)
			{
				arr[s] = 1;
				s *= i;
			}
			v *= s/i;
			s = i;
			while (s <= 20)
			{
				arr[s] = 1;
				s += i;
			}
		}
	}
	printf("%d\n", v);
}


Project Euler Share Tweet +1