Showing posts with label 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.. Show all posts
Showing posts with label 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.. Show all posts

Saturday, July 27, 2013

Project Euler Solved using C# : Smallest multiple


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?

 The Solution to this problem is very simple simply what one has to do is logically think what the question demands, The problem statement wants you to find the largest common factor to all the given numbers, so what you have to do is to find the largest common factor to all the numbers from1 to 20.

The program to solve this problem in C# is below, call this class in the "static main()" function and get the required solution. Answer to this problem is :232792560

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Text;  
 namespace ProjectEuler  
 {  
   class LargestCommonFactor  
   {  
     private int _upperlimit = 20;  
     private List<int> _primenumbers = new List<int>();  
     private List<int> _LCMcandidates = new List<int>();  
     public Dictionary<int, int> _primepowerpair = new Dictionary<int, int>();  
     public LargestCommonFactor()