fork download
  1. using System;
  2. using System.Diagnostics;
  3.  
  4. public class Test
  5. {
  6. public static long Euclid(long big, long small)
  7. {
  8. long mod = 0;
  9. while ((mod = big % small) != 0)
  10. {
  11. big = small;
  12. small = mod;
  13. }
  14. return small;
  15. }
  16.  
  17. public static long GCD(long left, long right) {
  18. if (left > right) {
  19. return Euclid(left, right);
  20. }
  21. return Euclid (right, left);
  22. }
  23.  
  24. public static long DZMin(int limit)
  25. {
  26. long multiple = limit;
  27. for (int m = limit - 1; m > 1; m--) {
  28. long prod = m * multiple;
  29. multiple = prod / GCD(multiple, m);
  30. Console.WriteLine("Multiple {0} product to {1} multiple {2}", m, prod, multiple);
  31.  
  32. }
  33. return multiple;
  34. }
  35.  
  36. public static int MinMultiples(int from)
  37. {
  38. int multiple = from;
  39. for (int m = from - 1; m > 1; m--)
  40. {
  41. int extend = multiple;
  42. Console.WriteLine("Multiple {0} extending by {1}", m, extend);
  43. while ((multiple % m) != 0)
  44. {
  45. multiple += extend;
  46. }
  47. }
  48. return multiple;
  49. }
  50.  
  51. public static void Main()
  52. {
  53. Stopwatch s = new Stopwatch();
  54. s.Start();
  55.  
  56. Console.WriteLine("Result {0}", MinMultiples(20));
  57.  
  58. s.Stop();
  59.  
  60. Console.WriteLine("The time took is {0} milliseconds.", s.ElapsedMilliseconds);
  61.  
  62. s.Reset();
  63.  
  64. s.Start();
  65.  
  66. Console.WriteLine("Result {0}", DZMin(20));
  67.  
  68. s.Stop();
  69.  
  70. Console.WriteLine("The time took is {0} milliseconds.", s.ElapsedMilliseconds);
  71.  
  72. }
  73. }
Success #stdin #stdout 0.03s 33912KB
stdin
Standard input is empty
stdout
Multiple 19 extending by 20
Multiple 18 extending by 380
Multiple 17 extending by 3420
Multiple 16 extending by 58140
Multiple 15 extending by 232560
Multiple 14 extending by 232560
Multiple 13 extending by 1627920
Multiple 12 extending by 21162960
Multiple 11 extending by 21162960
Multiple 10 extending by 232792560
Multiple 9 extending by 232792560
Multiple 8 extending by 232792560
Multiple 7 extending by 232792560
Multiple 6 extending by 232792560
Multiple 5 extending by 232792560
Multiple 4 extending by 232792560
Multiple 3 extending by 232792560
Multiple 2 extending by 232792560
Result 232792560
The time took is 24 milliseconds.
Multiple 19 product to 380 multiple 380
Multiple 18 product to 6840 multiple 3420
Multiple 17 product to 58140 multiple 58140
Multiple 16 product to 930240 multiple 232560
Multiple 15 product to 3488400 multiple 232560
Multiple 14 product to 3255840 multiple 1627920
Multiple 13 product to 21162960 multiple 21162960
Multiple 12 product to 253955520 multiple 21162960
Multiple 11 product to 232792560 multiple 232792560
Multiple 10 product to 2327925600 multiple 232792560
Multiple 9 product to 2095133040 multiple 232792560
Multiple 8 product to 1862340480 multiple 232792560
Multiple 7 product to 1629547920 multiple 232792560
Multiple 6 product to 1396755360 multiple 232792560
Multiple 5 product to 1163962800 multiple 232792560
Multiple 4 product to 931170240 multiple 232792560
Multiple 3 product to 698377680 multiple 232792560
Multiple 2 product to 465585120 multiple 232792560
Result 232792560
The time took is 1 milliseconds.