ProjectEuler Problem-5 Solution

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?

Solution :

#include<iostream>
using namespace std;

int main()
{
 int p=21;
    int flag=0;
 while(1)
 {
    for(int i=1;i<=20;i++)
    {
       if(p%i==0)
       {
        flag=1;
       }
       else
       flag=0;
       if(flag==0)
       break;
    } 
  if(flag==1)
  break;
  p++; 
 }
 cout<<p;
 return 0; 
 
}

No comments: