Fekke

Euler Problem1

Mar 21st, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. namespace Euler.Problems
  5. {
  6.     internal class Problem1
  7.     {
  8.         public static string[] Info()
  9.         {
  10.             string[] metadata =
  11.             {
  12.                 "Multiples of 3 and 5",
  13.                 "If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.\r\n\r\nFind the sum of all the multiples of 3 or 5 below 1000.",
  14.                 "1000"
  15.             };
  16.             return metadata;
  17.         }
  18.         public static BigInteger Solution(object[] args)
  19.         {
  20.             BigInteger
  21.                 a = 0,
  22.                 n = 0,
  23.                 i = BigInteger.Parse((string)args[0]);
  24.  
  25.             for (n = 1; n < i; n++)
  26.             {
  27.                 if (n % 3 == 0 || n % 5 == 0)
  28.                 {
  29.                     Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss]: ") + n);
  30.                     a = a + n;
  31.                 }
  32.             }
  33.             return a;
  34.         }
  35.         public static BigInteger GolfedSolution(object[] args)
  36.         {
  37.             BigInteger a = 0, n, i = BigInteger.Parse((string)args[0]);
  38.             for (n = 1; n < i; n++)
  39.             {
  40.                 if (n % 3 == 0 || n % 5 == 0)
  41.                 {
  42.                     a = a + n;
  43.                 }
  44.             }
  45.             return a;
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment