Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions C#/02.EvenFiboNumbers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Project Euler : Problem Number02
using System;
namespace _2._Even_Fibonacci_numbers
{
class EvenFiboNumbers
{
static int evenFibSum(int limit)
{
if (limit < 2)
return 0;

// Initialize first two even
// prime numbers and their sum
long ef1 = 0, ef2 = 2;
long sum = ef1 + ef2;

// calculating sum of even
// Fibonacci value
while (ef2 <= limit)
{

// get next even value of
// Fibonacci sequence
long ef3 = 4 * ef2 + ef1;

// If we go beyond limit,
// we break loop
if (ef3 > limit)
break;

// Move to next even number
// and update sum
ef1 = ef2;
ef2 = ef3;
sum += ef2;
}

return (int)sum;
}

// Driver code
public static void Main()
{
int limit = 4000000;
Console.Write(evenFibSum(limit));

}
}
}
26 changes: 26 additions & 0 deletions C#/03.largest_prime_fac.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//Euler problem03
using System;
namespace largest_prime_fac
{
class largest_prime_fac
{
public static void Main()
{
long num = 600851475143;
int count = 3;
while (num > 1)
{
if (num % count == 0)
{
num /= count;
}
else
{
count += 2;
}
}
Console.WriteLine("The largest prime factor of the number {0} is {1} ", 600851475143, count);
Console.ReadKey();
}
}
}
34 changes: 34 additions & 0 deletions C#/04.Largest_palindrome_product
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//Euler problem04
using System;
namespace _Largest_palindrome_product
{
class Largest_palindrome_product
{
public static void Main()
{
for (int i = 999; i >= 100; i--)
{
for (int j = 999; j >= 100; j--)
{
if (isPalindome(i * j) == true)
{
Console.WriteLine("Digit1: " + i);
Console.WriteLine("Digit2: " + j);
Console.WriteLine("Outcome: " + i * j);
Console.ReadLine();
}
}

}
Console.ReadLine();
}
public static bool isPalindome(int num)
{
string sNum = num.ToString();
for (int i = 0; i < sNum.Length / 2; i++)
if (sNum[i] != sNum[sNum.Length - 1 - i]) return false;

return true;
}
}
}
51 changes: 51 additions & 0 deletions C#/05.Smallest_multiple.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//Euler problem05
using System;
using System.Collections.Generic;
using System.Linq;

namespace _Smallest_multiple
{
class Smallest_multiple
{
public static void Main()
{
Console.WriteLine(Calc(20));
}
static List<int> Factors(int n)
{
List<int> list = new List<int>();
int i = 2;
while (i <= n)
{
if (n % i == 0)
{
list.Add(i);
n /= i;
}
else
i++;
}
return list;
}

static int Calc(int n)
{
var factors = Enumerable.Range(2, n - 1).Select(j => Factors(j)).ToList();

int i = 2;
int res = 1;
while (i <= n)
{
if (factors.Count(l => l.Contains(i)) > 1)
{
factors.ForEach(l => l.Remove(i));
res *= i;
}
else
i++;
}

return res * factors.SelectMany(x => x).Aggregate((s, j) => s *= j);
}
}
}
17 changes: 17 additions & 0 deletions C#/06.Sum_square_difference
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//Euler problem06
using System;

public class Sum_square_difference
{
public static void Main()
{
int n=10;
//sum of square first 100numbers
//1^2+2^2+3^2....
long sum1=(n*(n+1)*(2*n+1))/6;
//sum of first 100 numbers square
//(1+2+3...)^2
long sum2=((n*(n+1))/2)*((n*(n+1))/2);
Console.WriteLine(sum2-sum1);
}
}
27 changes: 27 additions & 0 deletions C#/07.Prime_10001st.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//Euler problem07
using System;
using System.Collections.Generic;
using System.Linq;

namespace _Prime_10001st
{
class Prime_10001st
{
public static void Main()
{
List<long> primeNumbers = new List<long>() { 2 };
for (long i = 3; i < long.MaxValue; i += 2)
{
if (!primeNumbers.Any(p => (i % p) == 0))
{
primeNumbers.Add(i);
if (primeNumbers.Count == 10001)
{
Console.WriteLine(i);
break;
}
}
}
}
}
}